diff --git a/Dockerfile b/Dockerfile index e7835b2b..ec7cc1b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ADD go.sum . RUN go mod download COPY pkg/ pkg/ -COPY api/ api/ +COPY apis/ apis/ COPY cmd/ cmd/ COPY controllers/ controllers/ COPY main.go main.go diff --git a/Makefile b/Makefile index 70090cb7..980d793c 100644 --- a/Makefile +++ b/Makefile @@ -26,8 +26,25 @@ GO111MODULE=on all: test manager addonctl # Run tests -test: generate fmt vet manifests - go test ./api/... ./controllers/... ./pkg/... ./cmd/... -coverprofile cover.out +.PHONY: test +test: + go test -v -race ./controllers/... ./apis/addon/... ./pkg/... ./cmd/... -coverprofile cover.out + +.PHONY: test.controllers +test.controllers: + go test -v -race ./controllers/... -coverprofile cover.out + +.PHONY: test.api +test.api: + go test -v -race ./apis/addon/... -coverprofile cover.out + +.PHONY: test.pkg +test.pkg: + go test -v -race ./pkg/... -coverprofile cover.out + +.PHONY: test.cmd +test.pkg: + go test -v -race ./cmd/... -coverprofile cover.out # Run E2E tests bdd: fmt vet deploy @@ -95,8 +112,13 @@ vet: go vet ./... # Generate code -generate: controller-gen - $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/... +generate: controller-gen code-generator + $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./apis/addon/... + bash $(GOPATH)/src/k8s.io/code-generator@v0.21.5/generate-groups.sh \ + "deepcopy,client,informer,lister" \ + github.com/keikoproj/addon-manager/pkg/client github.com/keikoproj/addon-manager/apis\ + addon:v1alpha1 \ + --go-header-file ./hack/custom-boilerplate.go.txt # Build the docker image docker-build: manager @@ -130,3 +152,15 @@ CONTROLLER_GEN=$(GOBIN)/controller-gen else CONTROLLER_GEN=$(shell which controller-gen) endif + +code-generator: +ifeq (, $(shell which code-generator)) + @{ \ + set -e ;\ + CODE_GENERATOR_DIR=$$(mkdir -p $(GOPATH)/src/k8s.io/) ;\ + cd $$CODE_GENERATOR_DIR ;\ + go get github.com/kubernetes/code-generator@v0.21.5 ;\ + } +endif + + diff --git a/apis/addon/register.go b/apis/addon/register.go new file mode 100644 index 00000000..e29c55f8 --- /dev/null +++ b/apis/addon/register.go @@ -0,0 +1,19 @@ +package addon + +import "time" + +// Addon constants +const ( + Group string = "addonmgr.keikoproj.io" + Version string = "v1alpha1" + APIVersion string = Group + "/" + Version + AddonKind string = "Addon" + AddonSingular string = "addon" + AddonPlural string = "addons" + AddonShortName string = "addon" + AddonFullName string = AddonPlural + "." + Group + + ManagedNameSpace string = "addon-manager-system" + + AddonResyncPeriod = 20 * time.Minute +) diff --git a/api/v1alpha1/addon_types.go b/apis/addon/v1alpha1/addon_types.go similarity index 98% rename from api/v1alpha1/addon_types.go rename to apis/addon/v1alpha1/addon_types.go index 4ce18c3f..c02ae8c3 100644 --- a/api/v1alpha1/addon_types.go +++ b/apis/addon/v1alpha1/addon_types.go @@ -151,6 +151,8 @@ const ( Deleting ApplicationAssemblyPhase = "Deleting" // DeleteFailed Used to indicate that delete failed. DeleteFailed ApplicationAssemblyPhase = "Delete Failed" + // Error used to indicate system error + Error ApplicationAssemblyPhase = "error" ) // DeploymentPhase represents the status of observed resources @@ -281,8 +283,8 @@ type AddonStatus struct { StartTime int64 `json:"starttime"` } +// AddonList contains a list of Addon // +kubebuilder:object:root=true - // Addon is the Schema for the addons API // +k8s:openapi-gen=true // +kubebuilder:subresource:status @@ -292,6 +294,8 @@ type AddonStatus struct { // +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.lifecycle.installed" // +kubebuilder:printcolumn:name="REASON",type="string",JSONPath=".status.reason" // +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type Addon struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -301,18 +305,13 @@ type Addon struct { } // +kubebuilder:object:root=true - -// AddonList contains a list of Addon +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type AddonList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` Items []Addon `json:"items"` } -func init() { - SchemeBuilder.Register(&Addon{}, &AddonList{}) -} - // GetPackageSpec returns the addon package details from addon spec func (a *Addon) GetPackageSpec() PackageSpec { return PackageSpec{ diff --git a/api/v1alpha1/addon_types_test.go b/apis/addon/v1alpha1/addon_types_test.go similarity index 82% rename from api/v1alpha1/addon_types_test.go rename to apis/addon/v1alpha1/addon_types_test.go index da112213..7d14f071 100644 --- a/api/v1alpha1/addon_types_test.go +++ b/apis/addon/v1alpha1/addon_types_test.go @@ -26,41 +26,41 @@ import ( ) var wfSpecTemplate = ` -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: scripts-python- -spec: - entrypoint: python-script-example - templates: - - name: python-script-example - steps: - - - name: generate - template: gen-random-int - - - name: print - template: print-message - arguments: - parameters: - - name: message - value: "{{steps.generate.outputs.result}}" - - - name: gen-random-int - script: - image: python:alpine3.6 - command: [python] - source: | - import random - i = random.randint(1, 100) - print(i) - - name: print-message - inputs: - parameters: - - name: message - container: - image: alpine:latest - command: [sh, -c] - args: ["echo result was: {{inputs.parameters.message}}"] -` + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: scripts-python- + spec: + entrypoint: python-script-example + templates: + - name: python-script-example + steps: + - - name: generate + template: gen-random-int + - - name: print + template: print-message + arguments: + parameters: + - name: message + value: "{{steps.generate.outputs.result}}" + + - name: gen-random-int + script: + image: python:alpine3.6 + command: [python] + source: | + import random + i = random.randint(1, 100) + print(i) + - name: print-message + inputs: + parameters: + - name: message + container: + image: alpine:latest + command: [sh, -c] + args: ["echo result was: {{inputs.parameters.message}}"] + ` // These tests are written in BDD-style using Ginkgo framework. Refer to // http://onsi.github.io/ginkgo to learn more. diff --git a/apis/addon/v1alpha1/doc.go b/apis/addon/v1alpha1/doc.go new file mode 100644 index 00000000..16789bf0 --- /dev/null +++ b/apis/addon/v1alpha1/doc.go @@ -0,0 +1,3 @@ +// +k8s:deepcopy-gen=package +// +groupName=addonmgr.keikoproj.io +package v1alpha1 diff --git a/api/v1alpha1/groupversion_info.go b/apis/addon/v1alpha1/groupversion_info.go similarity index 100% rename from api/v1alpha1/groupversion_info.go rename to apis/addon/v1alpha1/groupversion_info.go diff --git a/apis/addon/v1alpha1/register.go b/apis/addon/v1alpha1/register.go new file mode 100644 index 00000000..13917944 --- /dev/null +++ b/apis/addon/v1alpha1/register.go @@ -0,0 +1,23 @@ +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// SchemeGroupVersion is group version used to register these objects +var ( + SchemeGroupVersion = schema.GroupVersion{Group: "addonmgr.keikoproj.io", Version: "v1alpha1"} + AddonSchemaGroupVersionKind = schema.GroupVersionKind{Group: "addonmgr.keikoproj.io", Version: "v1alpha1", Kind: "Addon"} +) + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group-qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// Compitability, temp revert diff --git a/api/v1alpha1/suite_test.go b/apis/addon/v1alpha1/suit_test.go similarity index 97% rename from api/v1alpha1/suite_test.go rename to apis/addon/v1alpha1/suit_test.go index 6b97fad0..9688d26f 100644 --- a/api/v1alpha1/suite_test.go +++ b/apis/addon/v1alpha1/suit_test.go @@ -53,7 +53,7 @@ var _ = BeforeSuite(func(done Done) { CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, } - err := SchemeBuilder.AddToScheme(scheme.Scheme) + err := AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) cfg, err = testEnv.Start() diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/apis/addon/v1alpha1/zz_generated.deepcopy.go similarity index 99% rename from api/v1alpha1/zz_generated.deepcopy.go rename to apis/addon/v1alpha1/zz_generated.deepcopy.go index e09a9be1..fa86f044 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/apis/addon/v1alpha1/zz_generated.deepcopy.go @@ -20,7 +20,7 @@ package v1alpha1 import ( - runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/controllers/addon_controller.go b/controllers/addon_controller.go index 6efd863a..82fb9b0b 100644 --- a/controllers/addon_controller.go +++ b/controllers/addon_controller.go @@ -46,7 +46,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" "github.com/keikoproj/addon-manager/pkg/addon" "github.com/keikoproj/addon-manager/pkg/common" "github.com/keikoproj/addon-manager/pkg/workflows" diff --git a/controllers/addon_controller_test.go b/controllers/addon_controller_test.go index 4b01d6e5..b45cbf8f 100644 --- a/controllers/addon_controller_test.go +++ b/controllers/addon_controller_test.go @@ -16,7 +16,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" - "github.com/keikoproj/addon-manager/api/v1alpha1" + "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" ) var ( diff --git a/controllers/objects.go b/controllers/objects.go index cd72548c..7cce962a 100644 --- a/controllers/objects.go +++ b/controllers/objects.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" "sigs.k8s.io/controller-runtime/pkg/client" appsv1 "k8s.io/api/apps/v1" diff --git a/controllers/suite_test.go b/controllers/suite_test.go index ce41206c..b711e486 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -33,7 +33,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" // +kubebuilder:scaffold:imports ) diff --git a/main.go b/main.go index a38b5262..4c8cfc98 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" "github.com/keikoproj/addon-manager/controllers" "github.com/keikoproj/addon-manager/pkg/common" "github.com/keikoproj/addon-manager/pkg/version" diff --git a/pkg/addon/addon_validator.go b/pkg/addon/addon_validator.go index 58d2db9a..78dd52f9 100644 --- a/pkg/addon/addon_validator.go +++ b/pkg/addon/addon_validator.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" "github.com/keikoproj/addon-manager/pkg/common" ) diff --git a/pkg/addon/addon_validator_test.go b/pkg/addon/addon_validator_test.go index f714de59..e108037b 100644 --- a/pkg/addon/addon_validator_test.go +++ b/pkg/addon/addon_validator_test.go @@ -25,7 +25,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/dynamic/fake" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" ) var dynClient = fake.NewSimpleDynamicClient(runtime.NewScheme()) diff --git a/pkg/addon/addon_version_cache.go b/pkg/addon/addon_version_cache.go index 830e35ac..13a0e610 100644 --- a/pkg/addon/addon_version_cache.go +++ b/pkg/addon/addon_version_cache.go @@ -15,9 +15,10 @@ package addon import ( - "github.com/Masterminds/semver/v3" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" "sync" + + "github.com/Masterminds/semver/v3" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" ) // VersionCacheClient interface clients must implement for addon version cache. diff --git a/pkg/addon/addon_version_cache_test.go b/pkg/addon/addon_version_cache_test.go index 13877aee..30485b06 100644 --- a/pkg/addon/addon_version_cache_test.go +++ b/pkg/addon/addon_version_cache_test.go @@ -18,7 +18,7 @@ import ( "reflect" "testing" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" ) func TestNewCachedClient(t *testing.T) { diff --git a/pkg/addonctl/addonctl.go b/pkg/addonctl/addonctl.go index 58a20b54..534f8cd2 100644 --- a/pkg/addonctl/addonctl.go +++ b/pkg/addonctl/addonctl.go @@ -35,7 +35,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" "github.com/keikoproj/addon-manager/pkg/common" "github.com/keikoproj/addon-manager/pkg/version" "github.com/keikoproj/addon-manager/pkg/workflows" diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go new file mode 100644 index 00000000..aab19f47 --- /dev/null +++ b/pkg/client/clientset/versioned/clientset.go @@ -0,0 +1,81 @@ +// Code generated by client-gen. DO NOT EDIT. + +package versioned + +import ( + "fmt" + + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned/typed/addon/v1alpha1" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + AddonmgrV1alpha1() addonmgrv1alpha1.AddonmgrV1alpha1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + addonmgrV1alpha1 *addonmgrv1alpha1.AddonmgrV1alpha1Client +} + +// AddonmgrV1alpha1 retrieves the AddonmgrV1alpha1Client +func (c *Clientset) AddonmgrV1alpha1() addonmgrv1alpha1.AddonmgrV1alpha1Interface { + return c.addonmgrV1alpha1 +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. +func NewForConfig(c *rest.Config) (*Clientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } + configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) + } + var cs Clientset + var err error + cs.addonmgrV1alpha1, err = addonmgrv1alpha1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } + + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) + if err != nil { + return nil, err + } + return &cs, nil +} + +// NewForConfigOrDie creates a new Clientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Clientset { + var cs Clientset + cs.addonmgrV1alpha1 = addonmgrv1alpha1.NewForConfigOrDie(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) + return &cs +} + +// New creates a new Clientset for the given RESTClient. +func New(c rest.Interface) *Clientset { + var cs Clientset + cs.addonmgrV1alpha1 = addonmgrv1alpha1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/pkg/client/clientset/versioned/doc.go b/pkg/client/clientset/versioned/doc.go new file mode 100644 index 00000000..0e0c2a89 --- /dev/null +++ b/pkg/client/clientset/versioned/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated clientset. +package versioned diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 00000000..71f3abef --- /dev/null +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,66 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + clientset "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned/typed/addon/v1alpha1" + fakeaddonmgrv1alpha1 "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery + tracker testing.ObjectTracker +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() testing.ObjectTracker { + return c.tracker +} + +var _ clientset.Interface = &Clientset{} + +// AddonmgrV1alpha1 retrieves the AddonmgrV1alpha1Client +func (c *Clientset) AddonmgrV1alpha1() addonmgrv1alpha1.AddonmgrV1alpha1Interface { + return &fakeaddonmgrv1alpha1.FakeAddonmgrV1alpha1{Fake: &c.Fake} +} diff --git a/pkg/client/clientset/versioned/fake/doc.go b/pkg/client/clientset/versioned/fake/doc.go new file mode 100644 index 00000000..3630ed1c --- /dev/null +++ b/pkg/client/clientset/versioned/fake/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go new file mode 100644 index 00000000..cafa4f90 --- /dev/null +++ b/pkg/client/clientset/versioned/fake/register.go @@ -0,0 +1,40 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + addonmgrv1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/pkg/client/clientset/versioned/scheme/doc.go b/pkg/client/clientset/versioned/scheme/doc.go new file mode 100644 index 00000000..14db57a5 --- /dev/null +++ b/pkg/client/clientset/versioned/scheme/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go new file mode 100644 index 00000000..7e61a5a2 --- /dev/null +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -0,0 +1,40 @@ +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + addonmgrv1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(Scheme)) +} diff --git a/pkg/client/clientset/versioned/typed/addon/v1alpha1/addon.go b/pkg/client/clientset/versioned/typed/addon/v1alpha1/addon.go new file mode 100644 index 00000000..2dc8ec7d --- /dev/null +++ b/pkg/client/clientset/versioned/typed/addon/v1alpha1/addon.go @@ -0,0 +1,179 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + scheme "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// AddonsGetter has a method to return a AddonInterface. +// A group's client should implement this interface. +type AddonsGetter interface { + Addons(namespace string) AddonInterface +} + +// AddonInterface has methods to work with Addon resources. +type AddonInterface interface { + Create(ctx context.Context, addon *v1alpha1.Addon, opts v1.CreateOptions) (*v1alpha1.Addon, error) + Update(ctx context.Context, addon *v1alpha1.Addon, opts v1.UpdateOptions) (*v1alpha1.Addon, error) + UpdateStatus(ctx context.Context, addon *v1alpha1.Addon, opts v1.UpdateOptions) (*v1alpha1.Addon, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.Addon, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.AddonList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Addon, err error) + AddonExpansion +} + +// addons implements AddonInterface +type addons struct { + client rest.Interface + ns string +} + +// newAddons returns a Addons +func newAddons(c *AddonmgrV1alpha1Client, namespace string) *addons { + return &addons{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the addon, and returns the corresponding addon object, and an error if there is any. +func (c *addons) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Addon, err error) { + result = &v1alpha1.Addon{} + err = c.client.Get(). + Namespace(c.ns). + Resource("addons"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Addons that match those selectors. +func (c *addons) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.AddonList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.AddonList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("addons"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested addons. +func (c *addons) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("addons"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a addon and creates it. Returns the server's representation of the addon, and an error, if there is any. +func (c *addons) Create(ctx context.Context, addon *v1alpha1.Addon, opts v1.CreateOptions) (result *v1alpha1.Addon, err error) { + result = &v1alpha1.Addon{} + err = c.client.Post(). + Namespace(c.ns). + Resource("addons"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(addon). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a addon and updates it. Returns the server's representation of the addon, and an error, if there is any. +func (c *addons) Update(ctx context.Context, addon *v1alpha1.Addon, opts v1.UpdateOptions) (result *v1alpha1.Addon, err error) { + result = &v1alpha1.Addon{} + err = c.client.Put(). + Namespace(c.ns). + Resource("addons"). + Name(addon.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(addon). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *addons) UpdateStatus(ctx context.Context, addon *v1alpha1.Addon, opts v1.UpdateOptions) (result *v1alpha1.Addon, err error) { + result = &v1alpha1.Addon{} + err = c.client.Put(). + Namespace(c.ns). + Resource("addons"). + Name(addon.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(addon). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the addon and deletes it. Returns an error if one occurs. +func (c *addons) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("addons"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *addons) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("addons"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched addon. +func (c *addons) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Addon, err error) { + result = &v1alpha1.Addon{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("addons"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/addon/v1alpha1/addon_client.go b/pkg/client/clientset/versioned/typed/addon/v1alpha1/addon_client.go new file mode 100644 index 00000000..915dafe1 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/addon/v1alpha1/addon_client.go @@ -0,0 +1,73 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type AddonmgrV1alpha1Interface interface { + RESTClient() rest.Interface + AddonsGetter +} + +// AddonmgrV1alpha1Client is used to interact with features provided by the addonmgr.keikoproj.io group. +type AddonmgrV1alpha1Client struct { + restClient rest.Interface +} + +func (c *AddonmgrV1alpha1Client) Addons(namespace string) AddonInterface { + return newAddons(c, namespace) +} + +// NewForConfig creates a new AddonmgrV1alpha1Client for the given config. +func NewForConfig(c *rest.Config) (*AddonmgrV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &AddonmgrV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new AddonmgrV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *AddonmgrV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new AddonmgrV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *AddonmgrV1alpha1Client { + return &AddonmgrV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *AddonmgrV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/addon/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/addon/v1alpha1/doc.go new file mode 100644 index 00000000..93a7ca4e --- /dev/null +++ b/pkg/client/clientset/versioned/typed/addon/v1alpha1/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/doc.go new file mode 100644 index 00000000..2b5ba4c8 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/fake_addon.go b/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/fake_addon.go new file mode 100644 index 00000000..8132845c --- /dev/null +++ b/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/fake_addon.go @@ -0,0 +1,126 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeAddons implements AddonInterface +type FakeAddons struct { + Fake *FakeAddonmgrV1alpha1 + ns string +} + +var addonsResource = schema.GroupVersionResource{Group: "addonmgr.keikoproj.io", Version: "v1alpha1", Resource: "addons"} + +var addonsKind = schema.GroupVersionKind{Group: "addonmgr.keikoproj.io", Version: "v1alpha1", Kind: "Addon"} + +// Get takes name of the addon, and returns the corresponding addon object, and an error if there is any. +func (c *FakeAddons) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Addon, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(addonsResource, c.ns, name), &v1alpha1.Addon{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Addon), err +} + +// List takes label and field selectors, and returns the list of Addons that match those selectors. +func (c *FakeAddons) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.AddonList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(addonsResource, addonsKind, c.ns, opts), &v1alpha1.AddonList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.AddonList{ListMeta: obj.(*v1alpha1.AddonList).ListMeta} + for _, item := range obj.(*v1alpha1.AddonList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested addons. +func (c *FakeAddons) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(addonsResource, c.ns, opts)) + +} + +// Create takes the representation of a addon and creates it. Returns the server's representation of the addon, and an error, if there is any. +func (c *FakeAddons) Create(ctx context.Context, addon *v1alpha1.Addon, opts v1.CreateOptions) (result *v1alpha1.Addon, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(addonsResource, c.ns, addon), &v1alpha1.Addon{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Addon), err +} + +// Update takes the representation of a addon and updates it. Returns the server's representation of the addon, and an error, if there is any. +func (c *FakeAddons) Update(ctx context.Context, addon *v1alpha1.Addon, opts v1.UpdateOptions) (result *v1alpha1.Addon, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(addonsResource, c.ns, addon), &v1alpha1.Addon{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Addon), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeAddons) UpdateStatus(ctx context.Context, addon *v1alpha1.Addon, opts v1.UpdateOptions) (*v1alpha1.Addon, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(addonsResource, "status", c.ns, addon), &v1alpha1.Addon{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Addon), err +} + +// Delete takes name of the addon and deletes it. Returns an error if one occurs. +func (c *FakeAddons) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(addonsResource, c.ns, name), &v1alpha1.Addon{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeAddons) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(addonsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.AddonList{}) + return err +} + +// Patch applies the patch and returns the patched addon. +func (c *FakeAddons) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Addon, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(addonsResource, c.ns, name, pt, data, subresources...), &v1alpha1.Addon{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Addon), err +} diff --git a/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/fake_addon_client.go b/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/fake_addon_client.go new file mode 100644 index 00000000..a14a94a7 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/addon/v1alpha1/fake/fake_addon_client.go @@ -0,0 +1,24 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned/typed/addon/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeAddonmgrV1alpha1 struct { + *testing.Fake +} + +func (c *FakeAddonmgrV1alpha1) Addons(namespace string) v1alpha1.AddonInterface { + return &FakeAddons{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeAddonmgrV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/addon/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/addon/v1alpha1/generated_expansion.go new file mode 100644 index 00000000..8a302ab9 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/addon/v1alpha1/generated_expansion.go @@ -0,0 +1,5 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +type AddonExpansion interface{} diff --git a/pkg/client/informers/externalversions/addon/interface.go b/pkg/client/informers/externalversions/addon/interface.go new file mode 100644 index 00000000..b728763a --- /dev/null +++ b/pkg/client/informers/externalversions/addon/interface.go @@ -0,0 +1,30 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package addon + +import ( + v1alpha1 "github.com/keikoproj/addon-manager/pkg/client/informers/externalversions/addon/v1alpha1" + internalinterfaces "github.com/keikoproj/addon-manager/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/addon/v1alpha1/addon.go b/pkg/client/informers/externalversions/addon/v1alpha1/addon.go new file mode 100644 index 00000000..6640d91e --- /dev/null +++ b/pkg/client/informers/externalversions/addon/v1alpha1/addon.go @@ -0,0 +1,74 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + addonv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + versioned "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned" + internalinterfaces "github.com/keikoproj/addon-manager/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/keikoproj/addon-manager/pkg/client/listers/addon/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// AddonInformer provides access to a shared informer and lister for +// Addons. +type AddonInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.AddonLister +} + +type addonInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewAddonInformer constructs a new informer for Addon type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAddonInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAddonInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredAddonInformer constructs a new informer for Addon type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAddonInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.AddonmgrV1alpha1().Addons(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.AddonmgrV1alpha1().Addons(namespace).Watch(context.TODO(), options) + }, + }, + &addonv1alpha1.Addon{}, + resyncPeriod, + indexers, + ) +} + +func (f *addonInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredAddonInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *addonInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&addonv1alpha1.Addon{}, f.defaultInformer) +} + +func (f *addonInformer) Lister() v1alpha1.AddonLister { + return v1alpha1.NewAddonLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/addon/v1alpha1/interface.go b/pkg/client/informers/externalversions/addon/v1alpha1/interface.go new file mode 100644 index 00000000..f797ac06 --- /dev/null +++ b/pkg/client/informers/externalversions/addon/v1alpha1/interface.go @@ -0,0 +1,29 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + internalinterfaces "github.com/keikoproj/addon-manager/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // Addons returns a AddonInformer. + Addons() AddonInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// Addons returns a AddonInformer. +func (v *version) Addons() AddonInformer { + return &addonInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go new file mode 100644 index 00000000..0b5f65c9 --- /dev/null +++ b/pkg/client/informers/externalversions/factory.go @@ -0,0 +1,164 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + versioned "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned" + addon "github.com/keikoproj/addon-manager/pkg/client/informers/externalversions/addon" + internalinterfaces "github.com/keikoproj/addon-manager/pkg/client/informers/externalversions/internalinterfaces" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + for k, v := range resyncConfig { + factory.customResync[reflect.TypeOf(k)] = v + } + return factory + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.tweakListOptions = tweakListOptions + return factory + } +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.namespace = namespace + return factory + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + namespace: v1.NamespaceAll, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + factory = opt(factory) + } + + return factory +} + +// Start initializes all requested informers. +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InternalInformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + Addonmgr() addon.Interface +} + +func (f *sharedInformerFactory) Addonmgr() addon.Interface { + return addon.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go new file mode 100644 index 00000000..754db998 --- /dev/null +++ b/pkg/client/informers/externalversions/generic.go @@ -0,0 +1,46 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + v1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=addonmgr.keikoproj.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("addons"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Addonmgr().V1alpha1().Addons().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 00000000..46a724f4 --- /dev/null +++ b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,24 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + versioned "github.com/keikoproj/addon-manager/pkg/client/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" +) + +// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/client/listers/addon/v1alpha1/addon.go b/pkg/client/listers/addon/v1alpha1/addon.go new file mode 100644 index 00000000..a6706626 --- /dev/null +++ b/pkg/client/listers/addon/v1alpha1/addon.go @@ -0,0 +1,83 @@ +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// AddonLister helps list Addons. +// All objects returned here must be treated as read-only. +type AddonLister interface { + // List lists all Addons in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.Addon, err error) + // Addons returns an object that can list and get Addons. + Addons(namespace string) AddonNamespaceLister + AddonListerExpansion +} + +// addonLister implements the AddonLister interface. +type addonLister struct { + indexer cache.Indexer +} + +// NewAddonLister returns a new AddonLister. +func NewAddonLister(indexer cache.Indexer) AddonLister { + return &addonLister{indexer: indexer} +} + +// List lists all Addons in the indexer. +func (s *addonLister) List(selector labels.Selector) (ret []*v1alpha1.Addon, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Addon)) + }) + return ret, err +} + +// Addons returns an object that can list and get Addons. +func (s *addonLister) Addons(namespace string) AddonNamespaceLister { + return addonNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// AddonNamespaceLister helps list and get Addons. +// All objects returned here must be treated as read-only. +type AddonNamespaceLister interface { + // List lists all Addons in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.Addon, err error) + // Get retrieves the Addon from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.Addon, error) + AddonNamespaceListerExpansion +} + +// addonNamespaceLister implements the AddonNamespaceLister +// interface. +type addonNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Addons in the indexer for a given namespace. +func (s addonNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Addon, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Addon)) + }) + return ret, err +} + +// Get retrieves the Addon from the indexer for a given namespace and name. +func (s addonNamespaceLister) Get(name string) (*v1alpha1.Addon, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("addon"), name) + } + return obj.(*v1alpha1.Addon), nil +} diff --git a/pkg/client/listers/addon/v1alpha1/expansion_generated.go b/pkg/client/listers/addon/v1alpha1/expansion_generated.go new file mode 100644 index 00000000..3393b257 --- /dev/null +++ b/pkg/client/listers/addon/v1alpha1/expansion_generated.go @@ -0,0 +1,11 @@ +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +// AddonListerExpansion allows custom methods to be added to +// AddonLister. +type AddonListerExpansion interface{} + +// AddonNamespaceListerExpansion allows custom methods to be added to +// AddonNamespaceLister. +type AddonNamespaceListerExpansion interface{} diff --git a/pkg/common/scheme.go b/pkg/common/scheme.go index 3c3f4666..77dda37f 100644 --- a/pkg/common/scheme.go +++ b/pkg/common/scheme.go @@ -2,7 +2,7 @@ package common import ( wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" diff --git a/pkg/workflows/workflow.go b/pkg/workflows/workflow.go index afb87210..dd3c5126 100644 --- a/pkg/workflows/workflow.go +++ b/pkg/workflows/workflow.go @@ -35,7 +35,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" "github.com/keikoproj/addon-manager/pkg/common" ) diff --git a/pkg/workflows/workflow_test.go b/pkg/workflows/workflow_test.go index 9bd5dabe..c04bc7fa 100644 --- a/pkg/workflows/workflow_test.go +++ b/pkg/workflows/workflow_test.go @@ -32,7 +32,7 @@ import ( "k8s.io/client-go/tools/record" runtimefake "sigs.k8s.io/controller-runtime/pkg/client/fake" - "github.com/keikoproj/addon-manager/api/v1alpha1" + "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" "github.com/keikoproj/addon-manager/pkg/common" ) diff --git a/test-bdd/main_test.go b/test-bdd/main_test.go index f3157e8f..7d446945 100644 --- a/test-bdd/main_test.go +++ b/test-bdd/main_test.go @@ -20,7 +20,8 @@ import ( "io/ioutil" "testing" - addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1" + addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1" + "github.com/keikoproj/addon-manager/pkg/common" "github.com/keikoproj/addon-manager/test-bdd/testutil" . "github.com/onsi/ginkgo"