mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Address comments.
This commit is contained in:
parent
4a148f99d6
commit
ec22c2dd82
19
pkg/client/unversioned/cache/listers.go
vendored
19
pkg/client/unversioned/cache/listers.go
vendored
@ -248,10 +248,10 @@ func (s *StoreToDaemonLister) List() (daemons []api.Daemon, err error) {
|
|||||||
return daemons, nil
|
return daemons, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPodDaemon returns a list of daemon daemons managing a pod. Returns an error iff no matching daemons are found.
|
// GetPodDaemons returns a list of daemons managing a pod. Returns an error iff no matching daemons are found.
|
||||||
func (s *StoreToDaemonLister) GetPodDaemon(pod *api.Pod) (daemons []api.Daemon, err error) {
|
func (s *StoreToDaemonLister) GetPodDaemons(pod *api.Pod) (daemons []api.Daemon, err error) {
|
||||||
var selector labels.Selector
|
var selector labels.Selector
|
||||||
var dc api.Daemon
|
var daemonController api.Daemon
|
||||||
|
|
||||||
if len(pod.Labels) == 0 {
|
if len(pod.Labels) == 0 {
|
||||||
err = fmt.Errorf("No daemons found for pod %v because it has no labels", pod.Name)
|
err = fmt.Errorf("No daemons found for pod %v because it has no labels", pod.Name)
|
||||||
@ -259,18 +259,17 @@ func (s *StoreToDaemonLister) GetPodDaemon(pod *api.Pod) (daemons []api.Daemon,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, m := range s.Store.List() {
|
for _, m := range s.Store.List() {
|
||||||
dc = *m.(*api.Daemon)
|
daemonController = *m.(*api.Daemon)
|
||||||
if dc.Namespace != pod.Namespace {
|
if daemonController.Namespace != pod.Namespace {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
labelSet := labels.Set(dc.Spec.Selector)
|
selector = labels.Set(daemonController.Spec.Selector).AsSelector()
|
||||||
selector = labels.Set(dc.Spec.Selector).AsSelector()
|
|
||||||
|
|
||||||
// If an dc with a nil or empty selector creeps in, it should match nothing, not everything.
|
// If a daemonController with a nil or empty selector creeps in, it should match nothing, not everything.
|
||||||
if labelSet.AsSelector().Empty() || !selector.Matches(labels.Set(pod.Labels)) {
|
if selector.Empty() || !selector.Matches(labels.Set(pod.Labels)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
daemons = append(daemons, dc)
|
daemons = append(daemons, daemonController)
|
||||||
}
|
}
|
||||||
if len(daemons) == 0 {
|
if len(daemons) == 0 {
|
||||||
err = fmt.Errorf("Could not find daemons for pod %s in namespace %s with labels: %v", pod.Name, pod.Namespace, pod.Labels)
|
err = fmt.Errorf("Could not find daemons for pod %s in namespace %s with labels: %v", pod.Name, pod.Namespace, pod.Labels)
|
||||||
|
10
pkg/client/unversioned/cache/listers_test.go
vendored
10
pkg/client/unversioned/cache/listers_test.go
vendored
@ -64,7 +64,7 @@ func TestStoreToReplicationControllerLister(t *testing.T) {
|
|||||||
},
|
},
|
||||||
outRCNames: util.NewStringSet("basic"),
|
outRCNames: util.NewStringSet("basic"),
|
||||||
},
|
},
|
||||||
// No pod lables
|
// No pod labels
|
||||||
{
|
{
|
||||||
inRCs: []*api.ReplicationController{
|
inRCs: []*api.ReplicationController{
|
||||||
{
|
{
|
||||||
@ -186,7 +186,7 @@ func TestStoreToDaemonLister(t *testing.T) {
|
|||||||
},
|
},
|
||||||
outDCNames: util.NewStringSet("basic", "complex", "complex2"),
|
outDCNames: util.NewStringSet("basic", "complex", "complex2"),
|
||||||
},
|
},
|
||||||
// No pod lables
|
// No pod labels
|
||||||
{
|
{
|
||||||
inDCs: []*api.Daemon{
|
inDCs: []*api.Daemon{
|
||||||
{
|
{
|
||||||
@ -200,7 +200,7 @@ func TestStoreToDaemonLister(t *testing.T) {
|
|||||||
pod := &api.Pod{
|
pod := &api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "pod1", Namespace: "ns"},
|
ObjectMeta: api.ObjectMeta{Name: "pod1", Namespace: "ns"},
|
||||||
}
|
}
|
||||||
return lister.GetPodDaemon(pod)
|
return lister.GetPodDaemons(pod)
|
||||||
},
|
},
|
||||||
outDCNames: util.NewStringSet(),
|
outDCNames: util.NewStringSet(),
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
@ -220,7 +220,7 @@ func TestStoreToDaemonLister(t *testing.T) {
|
|||||||
Labels: map[string]string{"foo": "bar"},
|
Labels: map[string]string{"foo": "bar"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return lister.GetPodDaemon(pod)
|
return lister.GetPodDaemons(pod)
|
||||||
},
|
},
|
||||||
outDCNames: util.NewStringSet(),
|
outDCNames: util.NewStringSet(),
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
@ -249,7 +249,7 @@ func TestStoreToDaemonLister(t *testing.T) {
|
|||||||
Namespace: "ns",
|
Namespace: "ns",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return lister.GetPodDaemon(pod)
|
return lister.GetPodDaemons(pod)
|
||||||
},
|
},
|
||||||
outDCNames: util.NewStringSet("bar"),
|
outDCNames: util.NewStringSet("bar"),
|
||||||
},
|
},
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package client
|
package unversioned
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -47,6 +47,9 @@ func newDaemons(c *Client, namespace string) *daemons {
|
|||||||
return &daemons{c, namespace}
|
return &daemons{c, namespace}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure statically that daemons implements DaemonInterface.
|
||||||
|
var _ DaemonInterface = &daemons{}
|
||||||
|
|
||||||
func (c *daemons) List(selector labels.Selector) (result *api.DaemonList, err error) {
|
func (c *daemons) List(selector labels.Selector) (result *api.DaemonList, err error) {
|
||||||
result = &api.DaemonList{}
|
result = &api.DaemonList{}
|
||||||
err = c.r.Get().Namespace(c.ns).Resource("daemons").LabelsSelectorParam(selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("daemons").LabelsSelectorParam(selector).Do().Into(result)
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package client
|
package unversioned
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -18,6 +18,7 @@ package testclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
kClientLib "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
"k8s.io/kubernetes/pkg/labels"
|
"k8s.io/kubernetes/pkg/labels"
|
||||||
"k8s.io/kubernetes/pkg/watch"
|
"k8s.io/kubernetes/pkg/watch"
|
||||||
@ -39,6 +40,9 @@ const (
|
|||||||
CreateDaemonAction = "create-daemon"
|
CreateDaemonAction = "create-daemon"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Ensure statically that FakeDaemons implements DaemonInterface.
|
||||||
|
var _ kClientLib.DaemonInterface = &FakeDaemons{}
|
||||||
|
|
||||||
func (c *FakeDaemons) Get(name string) (*api.Daemon, error) {
|
func (c *FakeDaemons) Get(name string) (*api.Daemon, error) {
|
||||||
obj, err := c.Fake.Invokes(NewGetAction("daemons", c.Namespace, name), &api.Daemon{})
|
obj, err := c.Fake.Invokes(NewGetAction("daemons", c.Namespace, name), &api.Daemon{})
|
||||||
return obj.(*api.Daemon), err
|
return obj.(*api.Daemon), err
|
@ -14,6 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package daemon provides Registry interface and it's RESTStorage
|
// Package daemon provides Registry interface and its RESTStorage
|
||||||
// implementation for storing Daemon api objects.
|
// implementation for storing Daemon api objects.
|
||||||
package daemon
|
package daemon
|
||||||
|
@ -543,28 +543,11 @@ func TestEtcdWatchControllersFields(t *testing.T) {
|
|||||||
|
|
||||||
testFieldMap := map[int][]fields.Set{
|
testFieldMap := map[int][]fields.Set{
|
||||||
PASS: {
|
PASS: {
|
||||||
{"status.currentNumberScheduled": "2"},
|
|
||||||
{"status.numberMisscheduled": "1"},
|
|
||||||
{"status.desiredNumberScheduled": "4"},
|
|
||||||
{"metadata.name": "foo"},
|
{"metadata.name": "foo"},
|
||||||
{"status.currentNumberScheduled": "2", "status.numberMisscheduled": "1"},
|
|
||||||
{"status.currentNumberScheduled": "2", "status.desiredNumberScheduled": "4"},
|
|
||||||
{"status.currentNumberScheduled": "2", "metadata.name": "foo"},
|
|
||||||
{"status.desiredNumberScheduled": "4", "metadata.name": "foo"},
|
|
||||||
{"status.currentNumberScheduled": "2", "status.desiredNumberScheduled": "4", "metadata.name": "foo"},
|
|
||||||
{"status.currentNumberScheduled": "2", "status.numberMisscheduled": "1", "status.desiredNumberScheduled": "4"},
|
|
||||||
{"status.currentNumberScheduled": "2", "status.numberMisscheduled": "1", "status.desiredNumberScheduled": "4", "metadata.name": "foo"},
|
|
||||||
},
|
},
|
||||||
FAIL: {
|
FAIL: {
|
||||||
{"status.currentNumberScheduled": "1"},
|
|
||||||
{"status.numberMisscheduled": "0"},
|
|
||||||
{"status.desiredNumberScheduled": "5"},
|
|
||||||
{"metadata.name": "bar"},
|
{"metadata.name": "bar"},
|
||||||
{"name": "foo"},
|
{"name": "foo"},
|
||||||
{"status.replicas": "0"},
|
|
||||||
{"status.currentNumberScheduled": "2", "status.desiredNumberScheduled": "3"},
|
|
||||||
{"status.numberMisscheduled": "3", "status.desiredNumberScheduled": "5"},
|
|
||||||
{"status.currentNumberScheduled": "2", "status.desiredNumberScheduled": "4", "metadata.name": "foox"},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testEtcdActions := []string{
|
testEtcdActions := []string{
|
||||||
|
@ -19,7 +19,6 @@ package daemon
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/validation"
|
"k8s.io/kubernetes/pkg/api/validation"
|
||||||
@ -92,17 +91,15 @@ func (daemonStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) f
|
|||||||
return append(validationErrorList, updateErrorList...)
|
return append(validationErrorList, updateErrorList...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowUnconditionalUpdate is the default update policy for daemon objects.
|
||||||
func (daemonStrategy) AllowUnconditionalUpdate() bool {
|
func (daemonStrategy) AllowUnconditionalUpdate() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// DaemonToSelectableFields returns a label set that represents the object.
|
// DaemonToSelectableFields returns a field set that represents the object.
|
||||||
func DaemonToSelectableFields(daemon *api.Daemon) fields.Set {
|
func DaemonToSelectableFields(daemon *api.Daemon) fields.Set {
|
||||||
return fields.Set{
|
return fields.Set{
|
||||||
"metadata.name": daemon.Name,
|
"metadata.name": daemon.Name,
|
||||||
"status.currentNumberScheduled": strconv.Itoa(daemon.Status.CurrentNumberScheduled),
|
|
||||||
"status.numberMisscheduled": strconv.Itoa(daemon.Status.NumberMisscheduled),
|
|
||||||
"status.desiredNumberScheduled": strconv.Itoa(daemon.Status.DesiredNumberScheduled),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if newVersion != version {
|
if newVersion != version {
|
||||||
return nil, nil, kubeerr.NewConflict(e.EndpointName, name, fmt.Errorf("the object has been modified; please apply your changes to the latest version and try again %+v, %+v", version, newVersion))
|
return nil, nil, kubeerr.NewConflict(e.EndpointName, name, fmt.Errorf("the object has been modified; please apply your changes to the latest version and try again"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := rest.BeforeUpdate(e.UpdateStrategy, ctx, obj, existing); err != nil {
|
if err := rest.BeforeUpdate(e.UpdateStrategy, ctx, obj, existing); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user