forked from aws/eks-anywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use kubectl for kube-proxy upgrader calls
Before the kube-proxy upgrader (aws#5345) all API calls to the management cluster came either from kubectl or clusterctl, which both happened to be run in a docker container in the admin machine. This was the first piece of code that introduced the use of Kubernetes Go client directly from the CLI binary. This means that if a user was relying on this internal implementation (explicit interface vs implicit interface), their system could break if it wasn't setup to give the CLI network connectivity to the kind cluster. This PR "reverts" the addition of that new paradigm byt changing the underlying client implementation to use kubectl commands.
- Loading branch information
Showing
30 changed files
with
2,042 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// Object is a Kubernetes object. | ||
type Object client.Object | ||
|
||
// ObjectList is a Kubernetes object list. | ||
type ObjectList client.ObjectList | ||
|
||
// Client is Kubernetes API client. | ||
type Client interface { | ||
Reader | ||
Writer | ||
} | ||
|
||
// Reader knows how to read and list Kubernetes objects. | ||
type Reader interface { | ||
// Get retrieves an obj for the given name and namespace from the Kubernetes Cluster. | ||
Get(ctx context.Context, name, namespace string, obj Object) error | ||
|
||
// List retrieves list of objects. On a successful call, Items field | ||
// in the list will be populated with the result returned from the server. | ||
List(ctx context.Context, list ObjectList) error | ||
} | ||
|
||
// Writer knows how to create, delete, and update Kubernetes objects. | ||
type Writer interface { | ||
// Create saves the object obj in the Kubernetes cluster. | ||
Create(ctx context.Context, obj Object) error | ||
|
||
// Update updates the given obj in the Kubernetes cluster. | ||
Update(ctx context.Context, obj Object) error | ||
|
||
// Delete deletes the given obj from Kubernetes cluster. | ||
Delete(ctx context.Context, obj Object) error | ||
|
||
// DeleteAllOf deletes all objects of the given type matching the given options. | ||
DeleteAllOf(ctx context.Context, obj Object, opts ...DeleteAllOfOption) error | ||
} | ||
|
||
// DeleteAllOfOption is some configuration that modifies options for a delete request. | ||
type DeleteAllOfOption interface { | ||
// ApplyToDeleteAllOf applies this configuration to the given deletecollection options. | ||
ApplyToDeleteAllOf(*DeleteAllOfOptions) | ||
} | ||
|
||
// DeleteAllOfOptions contains options for deletecollection (deleteallof) requests. | ||
type DeleteAllOfOptions struct { | ||
// HasLabels filters results by label and value. The requirement is an AND match | ||
// for all labels. | ||
HasLabels map[string]string | ||
|
||
// Namespace represents the namespace to list for, or empty for | ||
// non-namespaced objects, or to list across all namespaces. | ||
Namespace string | ||
} | ||
|
||
var _ DeleteAllOfOption = &DeleteAllOfOptions{} | ||
|
||
// ApplyToDeleteAllOf implements DeleteAllOfOption. | ||
func (o *DeleteAllOfOptions) ApplyToDeleteAllOf(do *DeleteAllOfOptions) { | ||
if o.HasLabels != nil { | ||
do.HasLabels = o.HasLabels | ||
} | ||
if o.Namespace != "" { | ||
do.Namespace = o.Namespace | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package kubernetes_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
"github.com/aws/eks-anywhere/pkg/clients/kubernetes" | ||
) | ||
|
||
func TestDeleteAllOfOptionsApplyToDeleteAllOf(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
option, in, want *kubernetes.DeleteAllOfOptions | ||
}{ | ||
{ | ||
name: "empty", | ||
option: &kubernetes.DeleteAllOfOptions{}, | ||
in: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{ | ||
"label": "value", | ||
}, | ||
Namespace: "ns", | ||
}, | ||
want: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{ | ||
"label": "value", | ||
}, | ||
Namespace: "ns", | ||
}, | ||
}, | ||
{ | ||
name: "only Namespace", | ||
option: &kubernetes.DeleteAllOfOptions{ | ||
Namespace: "other-ns", | ||
}, | ||
in: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{ | ||
"label": "value", | ||
}, | ||
Namespace: "ns", | ||
}, | ||
want: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{ | ||
"label": "value", | ||
}, | ||
Namespace: "other-ns", | ||
}, | ||
}, | ||
{ | ||
name: "Namespace and labels", | ||
option: &kubernetes.DeleteAllOfOptions{ | ||
Namespace: "other-ns", | ||
HasLabels: map[string]string{ | ||
"label2": "value2", | ||
}, | ||
}, | ||
in: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{ | ||
"label": "value", | ||
}, | ||
Namespace: "ns", | ||
}, | ||
want: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{ | ||
"label2": "value2", | ||
}, | ||
Namespace: "other-ns", | ||
}, | ||
}, | ||
{ | ||
name: "empty not nil labels", | ||
option: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{}, | ||
}, | ||
in: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{ | ||
"label": "value", | ||
}, | ||
Namespace: "ns", | ||
}, | ||
want: &kubernetes.DeleteAllOfOptions{ | ||
HasLabels: map[string]string{}, | ||
Namespace: "ns", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
tt.option.ApplyToDeleteAllOf(tt.in) | ||
g.Expect(tt.in).To(BeComparableTo(tt.want)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.