mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Change ContainsMinion to GetMinion
This commit is contained in:
parent
87b0b36212
commit
15e5b876b8
@ -430,17 +430,14 @@ func (r *Registry) CreateMinion(ctx api.Context, minion *api.Minion) error {
|
|||||||
return etcderr.InterpretCreateError(err, "minion", minion.ID)
|
return etcderr.InterpretCreateError(err, "minion", minion.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) ContainsMinion(ctx api.Context, minionID string) (bool, error) {
|
func (r *Registry) GetMinion(ctx api.Context, minionID string) (*api.Minion, error) {
|
||||||
var minion api.Minion
|
var minion api.Minion
|
||||||
key := makeMinionKey(minionID)
|
key := makeMinionKey(minionID)
|
||||||
err := r.ExtractObj(key, &minion, false)
|
err := r.ExtractObj(key, &minion, false)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
return true, nil
|
return nil, etcderr.InterpretGetError(err, "minion", minion.ID)
|
||||||
} else if tools.IsEtcdNotFound(err) {
|
|
||||||
return false, nil
|
|
||||||
} else {
|
|
||||||
return false, etcderr.InterpretGetError(err, "minion", minion.ID)
|
|
||||||
}
|
}
|
||||||
|
return &minion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) DeleteMinion(ctx api.Context, minionID string) error {
|
func (r *Registry) DeleteMinion(ctx api.Context, minionID string) error {
|
||||||
|
@ -1116,22 +1116,22 @@ func TestEtcdCreateMinion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdContainsMinion(t *testing.T) {
|
func TestEtcdGetMinion(t *testing.T) {
|
||||||
ctx := api.NewContext()
|
ctx := api.NewContext()
|
||||||
fakeClient := tools.NewFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.Set("/registry/minions/foo", runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{ID: "foo"}}), 0)
|
fakeClient.Set("/registry/minions/foo", runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{ID: "foo"}}), 0)
|
||||||
registry := NewTestEtcdRegistry(fakeClient)
|
registry := NewTestEtcdRegistry(fakeClient)
|
||||||
contains, err := registry.ContainsMinion(ctx, "foo")
|
minion, err := registry.GetMinion(ctx, "foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if contains == false {
|
if minion.ID != "foo" {
|
||||||
t.Errorf("Expected true, but got false")
|
t.Errorf("Unexpected minion: %#v", minion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdContainsMinionNotFound(t *testing.T) {
|
func TestEtcdGetMinionNotFound(t *testing.T) {
|
||||||
ctx := api.NewContext()
|
ctx := api.NewContext()
|
||||||
fakeClient := tools.NewFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/registry/minions/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/minions/foo"] = tools.EtcdResponseWithError{
|
||||||
@ -1141,14 +1141,10 @@ func TestEtcdContainsMinionNotFound(t *testing.T) {
|
|||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
registry := NewTestEtcdRegistry(fakeClient)
|
registry := NewTestEtcdRegistry(fakeClient)
|
||||||
contains, err := registry.ContainsMinion(ctx, "foo")
|
_, err := registry.GetMinion(ctx, "foo")
|
||||||
|
|
||||||
if err != nil {
|
if !errors.IsNotFound(err) {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("Unexpected error returned: %#v", err)
|
||||||
}
|
|
||||||
|
|
||||||
if contains == true {
|
|
||||||
t.Errorf("Expected false, but got true")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,21 +57,20 @@ func NewCachingRegistry(delegate Registry, ttl time.Duration) (Registry, error)
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CachingRegistry) ContainsMinion(ctx api.Context, nodeID string) (bool, error) {
|
func (r *CachingRegistry) GetMinion(ctx api.Context, nodeID string) (*api.Minion, error) {
|
||||||
if r.expired() {
|
if r.expired() {
|
||||||
if err := r.refresh(ctx, false); err != nil {
|
if err := r.refresh(ctx, false); err != nil {
|
||||||
return false, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// block updates in the middle of a contains.
|
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
for _, node := range r.nodes.Items {
|
for _, node := range r.nodes.Items {
|
||||||
if node.ID == nodeID {
|
if node.ID == nodeID {
|
||||||
return true, nil
|
return &node, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return nil, ErrDoesNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CachingRegistry) DeleteMinion(ctx api.Context, nodeID string) error {
|
func (r *CachingRegistry) DeleteMinion(ctx api.Context, nodeID string) error {
|
||||||
|
@ -37,18 +37,18 @@ func NewCloudRegistry(cloud cloudprovider.Interface, matchRE string, staticResou
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CloudRegistry) ContainsMinion(ctx api.Context, nodeID string) (bool, error) {
|
func (r *CloudRegistry) GetMinion(ctx api.Context, nodeID string) (*api.Minion, error) {
|
||||||
instances, err := r.ListMinions(ctx)
|
instances, err := r.ListMinions(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, node := range instances.Items {
|
for _, node := range instances.Items {
|
||||||
if node.ID == nodeID {
|
if node.ID == nodeID {
|
||||||
return true, nil
|
return &node, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return nil, ErrDoesNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r CloudRegistry) DeleteMinion(ctx api.Context, nodeID string) error {
|
func (r CloudRegistry) DeleteMinion(ctx api.Context, nodeID string) error {
|
||||||
|
@ -46,7 +46,7 @@ func TestCloudList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCloudContains(t *testing.T) {
|
func TestCloudGet(t *testing.T) {
|
||||||
ctx := api.NewContext()
|
ctx := api.NewContext()
|
||||||
instances := []string{"m1", "m2"}
|
instances := []string{"m1", "m2"}
|
||||||
fakeCloud := fake_cloud.FakeCloud{
|
fakeCloud := fake_cloud.FakeCloud{
|
||||||
@ -57,21 +57,21 @@ func TestCloudContains(t *testing.T) {
|
|||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
contains, err := registry.ContainsMinion(ctx, "m1")
|
minion, err := registry.GetMinion(ctx, "m1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !contains {
|
if minion == nil {
|
||||||
t.Errorf("Unexpected !contains")
|
t.Errorf("Unexpected !contains")
|
||||||
}
|
}
|
||||||
|
|
||||||
contains, err = registry.ContainsMinion(ctx, "m100")
|
minion, err = registry.GetMinion(ctx, "m100")
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected non error")
|
||||||
}
|
}
|
||||||
|
|
||||||
if contains {
|
if minion != nil {
|
||||||
t.Errorf("Unexpected contains")
|
t.Errorf("Unexpected contains")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,22 +40,22 @@ func NewHealthyRegistry(delegate Registry, client *http.Client) Registry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HealthyRegistry) ContainsMinion(ctx api.Context, minion string) (bool, error) {
|
func (r *HealthyRegistry) GetMinion(ctx api.Context, minionID string) (*api.Minion, error) {
|
||||||
contains, err := r.delegate.ContainsMinion(ctx, minion)
|
minion, err := r.delegate.GetMinion(ctx, minionID)
|
||||||
if err != nil {
|
if minion == nil {
|
||||||
return false, err
|
return nil, ErrDoesNotExist
|
||||||
}
|
}
|
||||||
if !contains {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
status, err := health.DoHTTPCheck(r.makeMinionURL(minion), r.client)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return nil, err
|
||||||
|
}
|
||||||
|
status, err := health.DoHTTPCheck(r.makeMinionURL(minionID), r.client)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
if status == health.Unhealthy {
|
if status == health.Unhealthy {
|
||||||
return false, nil
|
return nil, ErrNotHealty
|
||||||
}
|
}
|
||||||
return true, nil
|
return minion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HealthyRegistry) DeleteMinion(ctx api.Context, minionID string) error {
|
func (r *HealthyRegistry) DeleteMinion(ctx api.Context, minionID string) error {
|
||||||
|
@ -60,18 +60,18 @@ func TestBasicDelegation(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
ok, err := healthy.ContainsMinion(ctx, "m1")
|
minion, err := healthy.GetMinion(ctx, "m1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if !ok {
|
if minion == nil {
|
||||||
t.Errorf("Unexpected absence of 'm1'")
|
t.Errorf("Unexpected absence of 'm1'")
|
||||||
}
|
}
|
||||||
ok, err = healthy.ContainsMinion(ctx, "m5")
|
minion, err = healthy.GetMinion(ctx, "m5")
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected non-error")
|
||||||
}
|
}
|
||||||
if ok {
|
if minion != nil {
|
||||||
t.Errorf("Unexpected presence of 'm5'")
|
t.Errorf("Unexpected presence of 'm5'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,11 +104,11 @@ func TestFiltering(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(list, registrytest.MakeMinionList(expected, api.NodeResources{})) {
|
if !reflect.DeepEqual(list, registrytest.MakeMinionList(expected, api.NodeResources{})) {
|
||||||
t.Errorf("Expected %v, Got %v", expected, list)
|
t.Errorf("Expected %v, Got %v", expected, list)
|
||||||
}
|
}
|
||||||
ok, err := healthy.ContainsMinion(ctx, "m1")
|
minion, err := healthy.GetMinion(ctx, "m1")
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected non-error")
|
||||||
}
|
}
|
||||||
if ok {
|
if minion != nil {
|
||||||
t.Errorf("Unexpected presence of 'm1'")
|
t.Errorf("Unexpected presence of 'm1'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,6 @@ import "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|||||||
type Registry interface {
|
type Registry interface {
|
||||||
ListMinions(ctx api.Context) (*api.MinionList, error)
|
ListMinions(ctx api.Context) (*api.MinionList, error)
|
||||||
CreateMinion(ctx api.Context, minion *api.Minion) error
|
CreateMinion(ctx api.Context, minion *api.Minion) error
|
||||||
ContainsMinion(ctx api.Context, minionID string) (bool, error)
|
GetMinion(ctx api.Context, minionID string) (*api.Minion, error)
|
||||||
DeleteMinion(ctx api.Context, minionID string) error
|
DeleteMinion(ctx api.Context, minionID string) error
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ func NewREST(m Registry) *REST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ErrDoesNotExist = fmt.Errorf("The requested resource does not exist.")
|
var ErrDoesNotExist = fmt.Errorf("The requested resource does not exist.")
|
||||||
|
var ErrNotHealty = fmt.Errorf("The requested minion is not healthy.")
|
||||||
|
|
||||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||||
minion, ok := obj.(*api.Minion)
|
minion, ok := obj.(*api.Minion)
|
||||||
@ -56,20 +57,20 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
contains, err := rs.registry.ContainsMinion(ctx, minion.ID)
|
minion, err := rs.registry.GetMinion(ctx, minion.ID)
|
||||||
|
if minion == nil {
|
||||||
|
return nil, ErrDoesNotExist
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if contains {
|
return minion, nil
|
||||||
return rs.toApiMinion(minion.ID), nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("unable to add minion %#v", minion)
|
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error) {
|
||||||
exists, err := rs.registry.ContainsMinion(ctx, id)
|
minion, err := rs.registry.GetMinion(ctx, id)
|
||||||
if !exists {
|
if minion == nil {
|
||||||
return nil, ErrDoesNotExist
|
return nil, ErrDoesNotExist
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -81,11 +82,11 @@ func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||||
exists, err := rs.registry.ContainsMinion(ctx, id)
|
minion, err := rs.registry.GetMinion(ctx, id)
|
||||||
if !exists {
|
if minion == nil {
|
||||||
return nil, ErrDoesNotExist
|
return nil, ErrDoesNotExist
|
||||||
}
|
}
|
||||||
return rs.toApiMinion(id), err
|
return minion, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
|
||||||
|
@ -60,15 +60,15 @@ func (r *MinionRegistry) CreateMinion(ctx api.Context, minion *api.Minion) error
|
|||||||
return r.Err
|
return r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MinionRegistry) ContainsMinion(ctx api.Context, minionID string) (bool, error) {
|
func (r *MinionRegistry) GetMinion(ctx api.Context, minionID string) (*api.Minion, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
for _, node := range r.Minions.Items {
|
for _, node := range r.Minions.Items {
|
||||||
if node.ID == minionID {
|
if node.ID == minionID {
|
||||||
return true, r.Err
|
return &node, r.Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, r.Err
|
return nil, r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MinionRegistry) DeleteMinion(ctx api.Context, minionID string) error {
|
func (r *MinionRegistry) DeleteMinion(ctx api.Context, minionID string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user