diff --git a/Makefile b/Makefile index e8441b85..79c59b15 100644 --- a/Makefile +++ b/Makefile @@ -50,9 +50,9 @@ echo "Build Image $(IMAGE_NAME):$(IMAGE_TAG)" ; \ --build-arg GIT_COMMIT_VERSION=$(GIT_COMMIT_VERSION) \ --build-arg GIT_COMMIT_TIME=$(GIT_COMMIT_TIME) \ --build-arg VERSION=$(GIT_COMMIT_VERSION) \ - --build-arg BUILDPLATFORM="linux/$(TARGETARCH)" \ - --build-arg TARGETPLATFORM="linux/$(TARGETARCH)" \ - --build-arg TARGETARCH=$(TARGETARCH) \ + --build-arg BUILDPLATFORM="linux/$(ARCH)" \ + --build-arg TARGETPLATFORM="linux/$(ARCH)" \ + --build-arg TARGETARCH=$(ARCH) \ --build-arg TARGETOS=linux \ --file $(DOCKERFILE_PATH) \ --tag ${IMAGE_NAME}:$(IMAGE_TAG) . ; \ @@ -92,9 +92,9 @@ IMAGE_DIR=` dirname $(DOCKERFILE_PATH) ` ; \ echo "Build base image $(BASE_IMAGE_NAME):$${TAG}" ; \ docker build \ --build-arg USE_PROXY_SOURCE=true \ - --build-arg TARGETPLATFORM="linux/$(TARGETARCH)" \ - --build-arg BUILDPLATFORM="linux/$(TARGETARCH)" \ - --build-arg TARGETARCH=$(TARGETARCH) \ + --build-arg TARGETPLATFORM="linux/$(ARCH)" \ + --build-arg BUILDPLATFORM="linux/$(ARCH)" \ + --build-arg TARGETARCH=$(ARCH) \ --build-arg TARGETOS=linux \ --file $(DOCKERFILE_PATH) \ --output type=docker \ diff --git a/charts/crds/koffloader.koffloader.io_kclustergroups.yaml b/charts/crds/koffloader.koffloader.io_kclustergroups.yaml new file mode 100644 index 00000000..bd204afc --- /dev/null +++ b/charts/crds/koffloader.koffloader.io_kclustergroups.yaml @@ -0,0 +1,75 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: (unknown) + creationTimestamp: null + name: kclustergroups.koffloader.koffloader.io +spec: + group: koffloader.koffloader.io + names: + categories: + - koffloader + kind: KClusterGroup + listKind: KClusterGroupList + plural: kclustergroups + shortNames: + - kcg + singular: kclustergroup + scope: Cluster + versions: + - additionalPrinterColumns: + - description: clusterConnectorType + jsonPath: .spec.clusterConnectorType + name: clusterConnectorType + type: string + name: v1beta1 + schema: + openAPIV3Schema: + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + properties: + clusterConnector: + properties: + ciliumNamespace: + type: string + type: + type: string + type: object + kubeconfig: + properties: + secretName: + type: string + secretNamespace: + type: string + type: object + type: object + status: + properties: + clusterConnector: + type: string + kClusterGroup: + type: string + required: + - kClusterGroup + type: object + required: + - metadata + type: object + served: true + storage: true + subresources: + status: {} diff --git a/charts/crds/koffloader.koffloader.io_kclusters.yaml b/charts/crds/koffloader.koffloader.io_kclusters.yaml index 1a2a5ea4..6cddf6a1 100644 --- a/charts/crds/koffloader.koffloader.io_kclusters.yaml +++ b/charts/crds/koffloader.koffloader.io_kclusters.yaml @@ -11,28 +11,24 @@ spec: names: categories: - koffloader - kind: Kcluster - listKind: KclusterList + kind: KCluster + listKind: KClusterList plural: kclusters shortNames: - - mb + - kc singular: kcluster scope: Cluster versions: - additionalPrinterColumns: - - description: ipVersion - jsonPath: .spec.ipVersion - name: VERSION + - description: clusterConnector + jsonPath: .spec.clusterConnector.type + name: clusterConnector type: string - - description: subnet - jsonPath: .spec.subnet - name: SUBNET + - description: kClusterGroup + jsonPath: .status.kClusterGroup + name: kClusterGroup type: string - - description: totalIPCount - jsonPath: .status.totalIPCount - name: TOTAL-IP-COUNT - type: integer - name: v1 + name: v1beta1 schema: openAPIV3Schema: properties: @@ -50,133 +46,29 @@ spec: type: object spec: properties: - disable: - default: false - type: boolean - ipVersion: - enum: - - 4 - - 6 - format: int64 - type: integer - nodeAffinity: - description: A label selector is a label query over a set of resources. - The result of matchLabels and matchExpressions are ANDed. An empty - label selector matches all objects. A null label selector matches - no objects. + clusterConnector: properties: - matchExpressions: - description: matchExpressions is a list of label selector requirements. - The requirements are ANDed. - items: - description: A label selector requirement is a selector that - contains values, a key, and an operator that relates the key - and values. - properties: - key: - description: key is the label key that the selector applies - to. - type: string - operator: - description: operator represents a key's relationship to - a set of values. Valid operators are In, NotIn, Exists - and DoesNotExist. - type: string - values: - description: values is an array of string values. If the - operator is In or NotIn, the values array must be non-empty. - If the operator is Exists or DoesNotExist, the values - array must be empty. This array is replaced during a strategic - merge patch. - items: - type: string - type: array - required: - - key - - operator - type: object - type: array - matchLabels: - additionalProperties: - type: string - description: matchLabels is a map of {key,value} pairs. A single - {key,value} in the matchLabels map is equivalent to an element - of matchExpressions, whose key field is "key", the operator - is "In", and the values array contains only "value". The requirements - are ANDed. - type: object + ciliumNamespace: + type: string + type: + type: string type: object - x-kubernetes-map-type: atomic - podAffinity: - description: A label selector is a label query over a set of resources. - The result of matchLabels and matchExpressions are ANDed. An empty - label selector matches all objects. A null label selector matches - no objects. + kubeconfig: properties: - matchExpressions: - description: matchExpressions is a list of label selector requirements. - The requirements are ANDed. - items: - description: A label selector requirement is a selector that - contains values, a key, and an operator that relates the key - and values. - properties: - key: - description: key is the label key that the selector applies - to. - type: string - operator: - description: operator represents a key's relationship to - a set of values. Valid operators are In, NotIn, Exists - and DoesNotExist. - type: string - values: - description: values is an array of string values. If the - operator is In or NotIn, the values array must be non-empty. - If the operator is Exists or DoesNotExist, the values - array must be empty. This array is replaced during a strategic - merge patch. - items: - type: string - type: array - required: - - key - - operator - type: object - type: array - matchLabels: - additionalProperties: - type: string - description: matchLabels is a map of {key,value} pairs. A single - {key,value} in the matchLabels map is equivalent to an element - of matchExpressions, whose key field is "key", the operator - is "In", and the values array contains only "value". The requirements - are ANDed. - type: object + secretName: + type: string + secretNamespace: + type: string type: object - x-kubernetes-map-type: atomic - subnet: - type: string - vlan: - default: 0 - format: int64 - maximum: 4095 - minimum: 0 - type: integer - required: - - subnet type: object status: properties: - timeStamp: - format: date-time + clusterConnector: + type: string + kClusterGroup: type: string - totalIPCount: - format: int64 - minimum: 0 - type: integer required: - - totalIPCount + - kClusterGroup type: object required: - metadata diff --git a/charts/crds/koffloader.koffloader.io_serviceexportpolicies.yaml b/charts/crds/koffloader.koffloader.io_serviceexportpolicies.yaml new file mode 100644 index 00000000..9c8dc83f --- /dev/null +++ b/charts/crds/koffloader.koffloader.io_serviceexportpolicies.yaml @@ -0,0 +1,70 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: (unknown) + creationTimestamp: null + name: serviceexportpolicies.koffloader.koffloader.io +spec: + group: koffloader.koffloader.io + names: + categories: + - koffloader + kind: ServiceExportPolicy + listKind: ServiceExportPolicyList + plural: serviceexportpolicies + shortNames: + - sep + singular: serviceexportpolicy + scope: Cluster + versions: + - name: v1beta1 + schema: + openAPIV3Schema: + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + properties: + clusterConnector: + properties: + ciliumNamespace: + type: string + type: + type: string + type: object + kubeconfig: + properties: + secretName: + type: string + secretNamespace: + type: string + type: object + type: object + status: + properties: + clusterConnector: + type: string + kClusterGroup: + type: string + required: + - kClusterGroup + type: object + required: + - metadata + type: object + served: true + storage: true + subresources: + status: {} diff --git a/charts/templates/tls.yaml b/charts/templates/tls.yaml index b5b68293..38a978ba 100644 --- a/charts/templates/tls.yaml +++ b/charts/templates/tls.yaml @@ -18,7 +18,7 @@ webhooks: name: {{ .Values.koffloaderController.name | trunc 63 | trimSuffix "-" }} namespace: {{ .Release.Namespace }} # ====modify==== the mutating route path : "/mutate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind) - path: "/mutate-koffloader-koffloader-io-v1-kcluster" + path: "/mutate-koffloader-koffloader-io-v1beta1-kcluster" port: {{ .Values.koffloaderController.webhookPort }} {{- if (eq .Values.koffloaderController.tls.method "provided") }} caBundle: {{ .Values.koffloaderController.tls.provided.tlsCa | required "missing tls.provided.tlsCa" }} @@ -33,11 +33,10 @@ webhooks: # ====modify==== - koffloader.koffloader.io apiVersions: - - v1 + - v1beta1 operations: - CREATE - UPDATE - - DELETE resources: # ====modify==== crdName - kclusters @@ -60,7 +59,7 @@ webhooks: name: {{ .Values.koffloaderController.name | trunc 63 | trimSuffix "-" }} namespace: {{ .Release.Namespace }} # ====modify==== the validate route path : "/validate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind) - path: "/validate-koffloader-koffloader-io-v1-kcluster" + path: "/validate-koffloader-koffloader-io-v1beta1-kcluster" port: {{ .Values.koffloaderController.webhookPort }} {{- if (eq .Values.koffloaderController.tls.method "provided") }} caBundle: {{ .Values.koffloaderController.tls.provided.tlsCa | required "missing tls.provided.tlsCa" }} @@ -75,11 +74,10 @@ webhooks: # ====modify==== - koffloader.koffloader.io apiVersions: - - v1 + - v1beta1 operations: - CREATE - UPDATE - - DELETE resources: # ====modify==== crdName - kclusters diff --git a/cmd/controller/cmd/config.go b/cmd/controller/cmd/config.go index 36d57a8e..9c19b1ab 100644 --- a/cmd/controller/cmd/config.go +++ b/cmd/controller/cmd/config.go @@ -4,14 +4,16 @@ package cmd import ( - "github.com/koffloader-io/koffloader/pkg/logger" - "github.com/koffloader-io/koffloader/pkg/types" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "gopkg.in/yaml.v3" "os" "reflect" "strconv" + + "github.com/spf13/cobra" + "github.com/spf13/viper" + "gopkg.in/yaml.v3" + + "github.com/koffloader-io/koffloader/pkg/logger" + "github.com/koffloader-io/koffloader/pkg/types" ) func init() { @@ -25,16 +27,16 @@ func init() { rootLogger.Info("ENV_LOG_LEVEL is empty ") } - logger := rootLogger.Named("config") + l := rootLogger.Named("config") // env built in the image if t := viper.GetString("ENV_VERSION"); len(t) > 0 { - logger.Info("app version " + t) + l.Info("app version " + t) } if t := viper.GetString("ENV_GIT_COMMIT_VERSION"); len(t) > 0 { - logger.Info("git commit version " + t) + l.Info("git commit version " + t) } if t := viper.GetString("ENV_GIT_COMMIT_TIMESTAMP"); len(t) > 0 { - logger.Info("git commit timestamp " + t) + l.Info("git commit timestamp " + t) } for n, v := range types.ControllerEnvMapping { @@ -49,7 +51,7 @@ func init() { r := types.ControllerEnvMapping[n].DestVar.(*int32) *r = int32(s) } else { - logger.Fatal("failed to parse env value of " + v.EnvName + " to int32, value=" + m) + l.Fatal("failed to parse env value of " + v.EnvName + " to int32, value=" + m) } case *string: r := types.ControllerEnvMapping[n].DestVar.(*string) @@ -59,14 +61,14 @@ func init() { r := types.ControllerEnvMapping[n].DestVar.(*bool) *r = s } else { - logger.Fatal("failed to parse env value of " + v.EnvName + " to bool, value=" + m) + l.Fatal("failed to parse env value of " + v.EnvName + " to bool, value=" + m) } default: - logger.Sugar().Fatal("unsupported type to parse %v, config type=%v ", v.EnvName, reflect.TypeOf(v.DestVar)) + l.Sugar().Fatal("unsupported type to parse %v, config type=%v ", v.EnvName, reflect.TypeOf(v.DestVar)) } } - logger.Info(v.EnvName + " = " + m) + l.Info(v.EnvName + " = " + m) } // command flags @@ -76,22 +78,22 @@ func init() { globalFlag.StringVarP(&types.ControllerConfig.TlsServerCertPath, "tls-server-cert", "T", "", "server cert file path") globalFlag.StringVarP(&types.ControllerConfig.TlsServerKeyPath, "tls-server-key", "Y", "", "server key file path") if e := viper.BindPFlags(globalFlag); e != nil { - logger.Sugar().Fatalf("failed to BindPFlags, reason=%v", e) + l.Sugar().Fatalf("failed to BindPFlags, reason=%v", e) } printFlag := func() { - logger.Info("config-path = " + types.ControllerConfig.ConfigMapPath) - logger.Info("tls-ca-cert = " + types.ControllerConfig.TlsCaCertPath) - logger.Info("tls-server-cert = " + types.ControllerConfig.TlsServerCertPath) - logger.Info("tls-server-key = " + types.ControllerConfig.TlsServerKeyPath) + l.Info("config-path = " + types.ControllerConfig.ConfigMapPath) + l.Info("tls-ca-cert = " + types.ControllerConfig.TlsCaCertPath) + l.Info("tls-server-cert = " + types.ControllerConfig.TlsServerCertPath) + l.Info("tls-server-key = " + types.ControllerConfig.TlsServerKeyPath) // load configmap if len(types.ControllerConfig.ConfigMapPath) > 0 { configmapBytes, err := os.ReadFile(types.ControllerConfig.ConfigMapPath) if nil != err { - logger.Sugar().Fatalf("failed to read configmap file %v, error: %v", types.ControllerConfig.ConfigMapPath, err) + l.Sugar().Fatalf("failed to read configmap file %v, error: %v", types.ControllerConfig.ConfigMapPath, err) } if err := yaml.Unmarshal(configmapBytes, &types.ControllerConfig.Configmap); nil != err { - logger.Sugar().Fatalf("failed to parse configmap data, error: %v", err) + l.Sugar().Fatalf("failed to parse configmap data, error: %v", err) } } } diff --git a/cmd/controller/cmd/daemon.go b/cmd/controller/cmd/daemon.go index 91150918..bc554d44 100644 --- a/cmd/controller/cmd/daemon.go +++ b/cmd/controller/cmd/daemon.go @@ -5,15 +5,35 @@ package cmd import ( "context" - "github.com/koffloader-io/koffloader/pkg/debug" "github.com/koffloader-io/koffloader/pkg/kclusterManager" - "github.com/koffloader-io/koffloader/pkg/types" + "go.uber.org/zap" + "os" + "os/signal" + "path/filepath" + "syscall" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" - "path/filepath" - "time" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/koffloader-io/koffloader/pkg/debug" + koffloaderv1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + "github.com/koffloader-io/koffloader/pkg/types" ) +var scheme = runtime.NewScheme() + +func init() { + utilruntime.Must(koffloaderv1beta1.AddToScheme(scheme)) + utilruntime.Must(clientgoscheme.AddToScheme(scheme)) +} + func SetupUtility() { // run gops @@ -28,9 +48,8 @@ func SetupUtility() { } func DaemonMain() { - - rootLogger.Sugar().Infof("config: %+v", types.ControllerConfig) - + logger := rootLogger.Named("koffloader-controller") + logger.Sugar().Infof("config: %+v", types.ControllerConfig) SetupUtility() SetupHttpServer() @@ -51,12 +70,61 @@ func DaemonMain() { MetricHistogramDuration.Record(context.Background(), 10) MetricHistogramDuration.Record(context.Background(), 20) - // ---------- - s := kclusterManager.New(rootLogger.Named("kcluster")) - s.RunController("testlease", types.ControllerConfig.PodNamespace, types.ControllerConfig.PodName) - s.RunWebhookServer(int(types.ControllerConfig.WebhookPort), filepath.Dir(types.ControllerConfig.TlsServerCertPath)) + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ + Scheme: scheme, + MetricsBindAddress: "0", + HealthProbeBindAddress: "0", + + // lease + LeaderElection: true, + LeaderElectionNamespace: types.ControllerConfig.PodNamespace, + LeaderElectionID: types.ControllerElectorLockName, + + // webhook port + Port: int(types.ControllerConfig.WebhookPort), + CertDir: filepath.Dir(types.ControllerConfig.TlsServerCertPath), + + // for this not watched obj, get directly from api-server + ClientDisableCacheFor: []client.Object{ + &corev1.Node{}, + &corev1.Namespace{}, + &corev1.Pod{}, + &corev1.Service{}, + &appsv1.Deployment{}, + &appsv1.StatefulSet{}, + &appsv1.ReplicaSet{}, + &appsv1.DaemonSet{}, + }, + }) + if err != nil { + logger.Sugar().Fatalf("failed to NewManager, reason=%v", err) + } + // kcluster informer + kClusterInformer := kclusterManager.NewKClusterInformer(logger.Named("kClusterInformer")) + // setup kcluster webhook + (&kclusterManager.KClusterWebHook{ + Logger: logger.Named("KClusterWebHook"), + }).SetupWebhookWithManager(mgr) + + go func() { + logger.Info("Starting koffloader-controller runtime manager") + if err := mgr.Start(context.Background()); err != nil { + logger.Fatal(err.Error()) + } + }() + + kClusterInformer.SetupInformer(context.Background()) // ------------ - rootLogger.Info("hello world") - time.Sleep(time.Hour) + sigCh := make(chan os.Signal, 1) + signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT) + WatchSignal(logger, sigCh) +} + +func WatchSignal(logger *zap.Logger, sigCh chan os.Signal) { + for sig := range sigCh { + logger.Sugar().Warnw("received shutdown", "signal", sig) + // others... + + } } diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1/mybook_types.go b/pkg/k8s/apis/koffloader.koffloader.io/v1/mybook_types.go deleted file mode 100644 index 731dac41..00000000 --- a/pkg/k8s/apis/koffloader.koffloader.io/v1/mybook_types.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -// !!!!!! crd marker: -// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/markers/crd.go -// https://book.kubebuilder.io/reference/markers/crd.html -// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/markers/validation.go -// https://book.kubebuilder.io/reference/markers/crd-validation.html - -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type KclusterSpec struct { - // +kubebuilder:validation:Enum=4;6 - // +kubebuilder:validation:Optional - IPVersion *int64 `json:"ipVersion,omitempty"` - - // +kubebuilder:validation:Required - Subnet string `json:"subnet"` - - // +kubebuilder:default=false - // +kubebuilder:validation:Optional - Disable *bool `json:"disable,omitempty"` - - // +kubebuilder:default=0 - // +kubebuilder:validation:Maximum=4095 - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Optional - Vlan *int64 `json:"vlan,omitempty"` - - // +kubebuilder:validation:Optional - PodAffinity *metav1.LabelSelector `json:"podAffinity,omitempty"` - - // +kubebuilder:validation:Optional - NodeAffinity *metav1.LabelSelector `json:"nodeAffinity,omitempty"` -} - -type KclusterStatus struct { - // +kubebuilder:validation:Minimum=0 - TotalIPCount int64 `json:"totalIPCount"` - - // +kubebuilder:validation:Optional - // +kubebuilder:validation:Type:=string - // +kubebuilder:validation:Format:=date-time - TimeStamp *metav1.Time `json:"timeStamp,omitempty"` -} - -// scope(Namespaced or Cluster) -// +kubebuilder:resource:categories={koffloader},path="kclusters",singular="kcluster",scope="Cluster",shortName={mb} -// +kubebuilder:printcolumn:JSONPath=".spec.ipVersion",description="ipVersion",name="VERSION",type=string -// +kubebuilder:printcolumn:JSONPath=".spec.subnet",description="subnet",name="SUBNET",type=string -// +kubebuilder:printcolumn:JSONPath=".status.totalIPCount",description="totalIPCount",name="TOTAL-IP-COUNT",type=integer -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -// +genclient -// +genclient:nonNamespaced - -type Kcluster struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - - Spec KclusterSpec `json:"spec,omitempty"` - Status KclusterStatus `json:"status,omitempty"` -} - -// +kubebuilder:object:root=true - -type KclusterList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []Kcluster `json:"items"` -} - -func init() { - SchemeBuilder.Register(&Kcluster{}, &KclusterList{}) -} diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1/zz_generated.deepcopy.go b/pkg/k8s/apis/koffloader.koffloader.io/v1/zz_generated.deepcopy.go deleted file mode 100644 index bb00ec8d..00000000 --- a/pkg/k8s/apis/koffloader.koffloader.io/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,129 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by controller-gen. DO NOT EDIT. - -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Kcluster) DeepCopyInto(out *Kcluster) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Kcluster. -func (in *Kcluster) DeepCopy() *Kcluster { - if in == nil { - return nil - } - out := new(Kcluster) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Kcluster) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KclusterList) DeepCopyInto(out *KclusterList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Kcluster, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KclusterList. -func (in *KclusterList) DeepCopy() *KclusterList { - if in == nil { - return nil - } - out := new(KclusterList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *KclusterList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KclusterSpec) DeepCopyInto(out *KclusterSpec) { - *out = *in - if in.IPVersion != nil { - in, out := &in.IPVersion, &out.IPVersion - *out = new(int64) - **out = **in - } - if in.Disable != nil { - in, out := &in.Disable, &out.Disable - *out = new(bool) - **out = **in - } - if in.Vlan != nil { - in, out := &in.Vlan, &out.Vlan - *out = new(int64) - **out = **in - } - if in.PodAffinity != nil { - in, out := &in.PodAffinity, &out.PodAffinity - *out = new(metav1.LabelSelector) - (*in).DeepCopyInto(*out) - } - if in.NodeAffinity != nil { - in, out := &in.NodeAffinity, &out.NodeAffinity - *out = new(metav1.LabelSelector) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KclusterSpec. -func (in *KclusterSpec) DeepCopy() *KclusterSpec { - if in == nil { - return nil - } - out := new(KclusterSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KclusterStatus) DeepCopyInto(out *KclusterStatus) { - *out = *in - if in.TimeStamp != nil { - in, out := &in.TimeStamp, &out.TimeStamp - *out = (*in).DeepCopy() - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KclusterStatus. -func (in *KclusterStatus) DeepCopy() *KclusterStatus { - if in == nil { - return nil - } - out := new(KclusterStatus) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1/doc.go b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/doc.go similarity index 91% rename from pkg/k8s/apis/koffloader.koffloader.io/v1/doc.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1beta1/doc.go index a588dcf9..24c51fd7 100644 --- a/pkg/k8s/apis/koffloader.koffloader.io/v1/doc.go +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/doc.go @@ -3,4 +3,4 @@ // Package v1 is the v1 version of the API. // +groupName=koffloader.koffloader.io -package v1 +package v1beta1 diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1/groupversion_info.go b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/groupversion_info.go similarity index 94% rename from pkg/k8s/apis/koffloader.koffloader.io/v1/groupversion_info.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1beta1/groupversion_info.go index 9bd2447e..f80f2a76 100644 --- a/pkg/k8s/apis/koffloader.koffloader.io/v1/groupversion_info.go +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/groupversion_info.go @@ -5,7 +5,7 @@ // +groupName=koffloader.koffloader.io // Package v1 contains API Schema definitions for the spiderpool v1 API group -package v1 +package v1beta1 import ( "k8s.io/apimachinery/pkg/runtime/schema" @@ -14,7 +14,7 @@ import ( var ( // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "koffloader.koffloader.io", Version: "v1"} + GroupVersion = schema.GroupVersion{Group: "koffloader.koffloader.io", Version: "v1beta1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/kcluster_types.go b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/kcluster_types.go new file mode 100644 index 00000000..144ad425 --- /dev/null +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/kcluster_types.go @@ -0,0 +1,76 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// !!!!!! crd marker: +// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/markers/crd.go +// https://book.kubebuilder.io/reference/markers/crd.html +// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/markers/validation.go +// https://book.kubebuilder.io/reference/markers/crd-validation.html + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type KClusterSpec struct { + // +kubebuilder:validation:Required + ClusterConnector *ClusterConnectorType `json:"clusterConnector,omitempty"` + + // +kubebuilder:validation:Required + KubeConfig *Kubeconfig `json:"kubeconfig,omitempty"` +} + +type ClusterConnectorType struct { + // +kubebuilder:validation:Type:=string + Type string `json:"type,omitempty"` + + // +kubebuilder:validation:Type:=string + CiliumNamespace string `json:"ciliumNamespace,omitempty"` +} + +type Kubeconfig struct { + // +kubebuilder:validation:Type:=string + SecretName string `json:"secretName,omitempty"` + + // +kubebuilder:validation:Type:=string + SecretNamespace string `json:"secretNamespace,omitempty"` +} + +type KClusterStatus struct { + // +kubebuilder:validation:Type:=string + KClusterGroup string `json:"kClusterGroup"` + + // +kubebuilder:validation:Type:=string + ClusterConnector string `json:"clusterConnector,omitempty"` +} + +// scope(Namespaced or Cluster) +// +kubebuilder:resource:categories={koffloader},path="kclusters",singular="kcluster",scope="Cluster",shortName={kc} +// +kubebuilder:printcolumn:JSONPath=".spec.clusterConnector.type",description="clusterConnector",name="clusterConnector",type=string +// +kubebuilder:printcolumn:JSONPath=".status.kClusterGroup",description="kClusterGroup",name="kClusterGroup",type=string +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +genclient +// +genclient:nonNamespaced + +type KCluster struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + + Spec KClusterSpec `json:"spec,omitempty"` + Status KClusterStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +type KClusterList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []KCluster `json:"items"` +} + +func init() { + SchemeBuilder.Register(&KCluster{}, &KClusterList{}) +} diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/kclustergroup_types.go b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/kclustergroup_types.go new file mode 100644 index 00000000..c5d66e62 --- /dev/null +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/kclustergroup_types.go @@ -0,0 +1,59 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// !!!!!! crd marker: +// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/markers/crd.go +// https://book.kubebuilder.io/reference/markers/crd.html +// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/markers/validation.go +// https://book.kubebuilder.io/reference/markers/crd-validation.html + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type KClusterGroupSpec struct { + // +kubebuilder:validation:Required + ClusterConnectorType *string `json:"clusterConnectorType,omitempty"` + + // +kubebuilder:validation:Required + KClusterSelector *metav1.LabelSelector `json:"kClusterSelector,omitempty"` +} + +type KClusterGroupStatus struct { + // +kubebuilder:validation:Type:=string + MatchKCluster []string `json:"matchKCluster"` + + // +kubebuilder:validation:Type:=string + ClusterConnectorType string `json:"clusterConnectorType,omitempty"` +} + +// scope(Namespaced or Cluster) +// +kubebuilder:resource:categories={koffloader},path="kclustergroups",singular="kclustergroup",scope="Cluster",shortName={kcg} +// +kubebuilder:printcolumn:JSONPath=".spec.clusterConnectorType",description="clusterConnectorType",name="clusterConnectorType",type=string +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +genclient +// +genclient:nonNamespaced + +type KClusterGroup struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + + Spec KClusterSpec `json:"spec,omitempty"` + Status KClusterStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +type KClusterGroupList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []KCluster `json:"items"` +} + +func init() { + SchemeBuilder.Register(&KClusterGroup{}, &KClusterGroupList{}) +} diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1/rbac.go b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/rbac.go similarity index 98% rename from pkg/k8s/apis/koffloader.koffloader.io/v1/rbac.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1beta1/rbac.go index 26b53b33..627f40dc 100644 --- a/pkg/k8s/apis/koffloader.koffloader.io/v1/rbac.go +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/rbac.go @@ -14,4 +14,4 @@ // +kubebuilder:rbac:groups="batch",resources=jobs;cronjobs,verbs=get;list;update;watch // +kubebuilder:rbac:groups="",resources=nodes;namespaces;endpoints;pods,verbs=get;list;watch;update -package v1 +package v1beta1 diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1/register.go b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/register.go similarity index 96% rename from pkg/k8s/apis/koffloader.koffloader.io/v1/register.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1beta1/register.go index eca565eb..9a24413c 100644 --- a/pkg/k8s/apis/koffloader.koffloader.io/v1/register.go +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/register.go @@ -1,7 +1,7 @@ // Copyright 2024 Authors of koffloader-io // SPDX-License-Identifier: Apache-2.0 -package v1 +package v1beta1 import ( "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/serviceexportpolicy_types.go b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/serviceexportpolicy_types.go new file mode 100644 index 00000000..3e5daf4c --- /dev/null +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/serviceexportpolicy_types.go @@ -0,0 +1,77 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// !!!!!! crd marker: +// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/markers/crd.go +// https://book.kubebuilder.io/reference/markers/crd.html +// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/markers/validation.go +// https://book.kubebuilder.io/reference/markers/crd-validation.html + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type ServiceExportPolicySpec struct { + // +kubebuilder:validation:Required + CiliumServiceFeature *CiliumServiceFeature `json:"ciliumServiceFeature,omitempty"` + + // +kubebuilder:validation:Required + ServiceSelector *metav1.LabelSelector `json:"serviceSelector,omitempty"` + + // +kubebuilder:validation:Required + KClusterSelector *metav1.LabelSelector `json:"kclusterSelector,omitempty"` +} + +type CiliumServiceFeature struct { + // +kubebuilder:validation:Type:=bool + Share bool `json:"share,omitempty"` + + // +kubebuilder:validation:Type:=string + Affinity string `json:"affinity,omitempty"` + + // +kubebuilder:validation:Type:=bool + Global bool `json:"global,omitempty"` +} + +type ServiceExportPolicyStatus struct { + // +kubebuilder:validation:Type:=string + MatchKCluster []string `json:"matchKCluster,omitempty"` + + // +kubebuilder:validation:Optional + MatchService []ExportService `json:"matchService,omitempty"` +} + +type ExportService struct { + Name string `json:"name,omitempty"` + Namespace string `json:"namespace,omitempty"` +} + +// scope(Namespaced or Cluster) +// +kubebuilder:resource:categories={koffloader},path="serviceexportpolicies",singular="serviceexportpolicy",scope="Cluster",shortName={sep} +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +genclient +// +genclient:nonNamespaced + +type ServiceExportPolicy struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + + Spec KClusterSpec `json:"spec,omitempty"` + Status KClusterStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +type ServiceExportPolicyList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []KCluster `json:"items"` +} + +func init() { + SchemeBuilder.Register(&ServiceExportPolicy{}, &ServiceExportPolicyList{}) +} diff --git a/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/zz_generated.deepcopy.go b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/zz_generated.deepcopy.go new file mode 100644 index 00000000..ac1b6b81 --- /dev/null +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1beta1/zz_generated.deepcopy.go @@ -0,0 +1,388 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CiliumServiceFeature) DeepCopyInto(out *CiliumServiceFeature) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CiliumServiceFeature. +func (in *CiliumServiceFeature) DeepCopy() *CiliumServiceFeature { + if in == nil { + return nil + } + out := new(CiliumServiceFeature) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterConnectorType) DeepCopyInto(out *ClusterConnectorType) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConnectorType. +func (in *ClusterConnectorType) DeepCopy() *ClusterConnectorType { + if in == nil { + return nil + } + out := new(ClusterConnectorType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExportService) DeepCopyInto(out *ExportService) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExportService. +func (in *ExportService) DeepCopy() *ExportService { + if in == nil { + return nil + } + out := new(ExportService) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KCluster) DeepCopyInto(out *KCluster) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KCluster. +func (in *KCluster) DeepCopy() *KCluster { + if in == nil { + return nil + } + out := new(KCluster) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KCluster) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KClusterGroup) DeepCopyInto(out *KClusterGroup) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KClusterGroup. +func (in *KClusterGroup) DeepCopy() *KClusterGroup { + if in == nil { + return nil + } + out := new(KClusterGroup) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KClusterGroup) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KClusterGroupList) DeepCopyInto(out *KClusterGroupList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KCluster, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KClusterGroupList. +func (in *KClusterGroupList) DeepCopy() *KClusterGroupList { + if in == nil { + return nil + } + out := new(KClusterGroupList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KClusterGroupList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KClusterGroupSpec) DeepCopyInto(out *KClusterGroupSpec) { + *out = *in + if in.ClusterConnectorType != nil { + in, out := &in.ClusterConnectorType, &out.ClusterConnectorType + *out = new(string) + **out = **in + } + if in.KClusterSelector != nil { + in, out := &in.KClusterSelector, &out.KClusterSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KClusterGroupSpec. +func (in *KClusterGroupSpec) DeepCopy() *KClusterGroupSpec { + if in == nil { + return nil + } + out := new(KClusterGroupSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KClusterGroupStatus) DeepCopyInto(out *KClusterGroupStatus) { + *out = *in + if in.MatchKCluster != nil { + in, out := &in.MatchKCluster, &out.MatchKCluster + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KClusterGroupStatus. +func (in *KClusterGroupStatus) DeepCopy() *KClusterGroupStatus { + if in == nil { + return nil + } + out := new(KClusterGroupStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KClusterList) DeepCopyInto(out *KClusterList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KCluster, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KClusterList. +func (in *KClusterList) DeepCopy() *KClusterList { + if in == nil { + return nil + } + out := new(KClusterList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KClusterList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KClusterSpec) DeepCopyInto(out *KClusterSpec) { + *out = *in + if in.ClusterConnector != nil { + in, out := &in.ClusterConnector, &out.ClusterConnector + *out = new(ClusterConnectorType) + **out = **in + } + if in.KubeConfig != nil { + in, out := &in.KubeConfig, &out.KubeConfig + *out = new(Kubeconfig) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KClusterSpec. +func (in *KClusterSpec) DeepCopy() *KClusterSpec { + if in == nil { + return nil + } + out := new(KClusterSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KClusterStatus) DeepCopyInto(out *KClusterStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KClusterStatus. +func (in *KClusterStatus) DeepCopy() *KClusterStatus { + if in == nil { + return nil + } + out := new(KClusterStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Kubeconfig) DeepCopyInto(out *Kubeconfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Kubeconfig. +func (in *Kubeconfig) DeepCopy() *Kubeconfig { + if in == nil { + return nil + } + out := new(Kubeconfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceExportPolicy) DeepCopyInto(out *ServiceExportPolicy) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceExportPolicy. +func (in *ServiceExportPolicy) DeepCopy() *ServiceExportPolicy { + if in == nil { + return nil + } + out := new(ServiceExportPolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ServiceExportPolicy) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceExportPolicyList) DeepCopyInto(out *ServiceExportPolicyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KCluster, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceExportPolicyList. +func (in *ServiceExportPolicyList) DeepCopy() *ServiceExportPolicyList { + if in == nil { + return nil + } + out := new(ServiceExportPolicyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ServiceExportPolicyList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceExportPolicySpec) DeepCopyInto(out *ServiceExportPolicySpec) { + *out = *in + if in.CiliumServiceFeature != nil { + in, out := &in.CiliumServiceFeature, &out.CiliumServiceFeature + *out = new(CiliumServiceFeature) + **out = **in + } + if in.ServiceSelector != nil { + in, out := &in.ServiceSelector, &out.ServiceSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.KClusterSelector != nil { + in, out := &in.KClusterSelector, &out.KClusterSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceExportPolicySpec. +func (in *ServiceExportPolicySpec) DeepCopy() *ServiceExportPolicySpec { + if in == nil { + return nil + } + out := new(ServiceExportPolicySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceExportPolicyStatus) DeepCopyInto(out *ServiceExportPolicyStatus) { + *out = *in + if in.MatchKCluster != nil { + in, out := &in.MatchKCluster, &out.MatchKCluster + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.MatchService != nil { + in, out := &in.MatchService, &out.MatchService + *out = make([]ExportService, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceExportPolicyStatus. +func (in *ServiceExportPolicyStatus) DeepCopy() *ServiceExportPolicyStatus { + if in == nil { + return nil + } + out := new(ServiceExportPolicyStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/k8s/client/clientset/versioned/clientset.go b/pkg/k8s/client/clientset/versioned/clientset.go index 2e88cc95..0b175f88 100644 --- a/pkg/k8s/client/clientset/versioned/clientset.go +++ b/pkg/k8s/client/clientset/versioned/clientset.go @@ -9,7 +9,7 @@ import ( "fmt" "net/http" - koffloaderv1 "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1" + koffloaderv1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -17,18 +17,18 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface - KoffloaderV1() koffloaderv1.KoffloaderV1Interface + KoffloaderV1beta1() koffloaderv1beta1.KoffloaderV1beta1Interface } // Clientset contains the clients for groups. type Clientset struct { *discovery.DiscoveryClient - koffloaderV1 *koffloaderv1.KoffloaderV1Client + koffloaderV1beta1 *koffloaderv1beta1.KoffloaderV1beta1Client } -// KoffloaderV1 retrieves the KoffloaderV1Client -func (c *Clientset) KoffloaderV1() koffloaderv1.KoffloaderV1Interface { - return c.koffloaderV1 +// KoffloaderV1beta1 retrieves the KoffloaderV1beta1Client +func (c *Clientset) KoffloaderV1beta1() koffloaderv1beta1.KoffloaderV1beta1Interface { + return c.koffloaderV1beta1 } // Discovery retrieves the DiscoveryClient @@ -75,7 +75,7 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, var cs Clientset var err error - cs.koffloaderV1, err = koffloaderv1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.koffloaderV1beta1, err = koffloaderv1beta1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } @@ -100,7 +100,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { // New creates a new Clientset for the given RESTClient. func New(c rest.Interface) *Clientset { var cs Clientset - cs.koffloaderV1 = koffloaderv1.New(c) + cs.koffloaderV1beta1 = koffloaderv1beta1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/k8s/client/clientset/versioned/fake/clientset_generated.go b/pkg/k8s/client/clientset/versioned/fake/clientset_generated.go index 8e34ed3a..1c19065c 100644 --- a/pkg/k8s/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/k8s/client/clientset/versioned/fake/clientset_generated.go @@ -7,8 +7,8 @@ package fake import ( clientset "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned" - koffloaderv1 "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1" - fakekoffloaderv1 "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake" + koffloaderv1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1" + fakekoffloaderv1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" @@ -66,7 +66,7 @@ var ( _ testing.FakeClient = &Clientset{} ) -// KoffloaderV1 retrieves the KoffloaderV1Client -func (c *Clientset) KoffloaderV1() koffloaderv1.KoffloaderV1Interface { - return &fakekoffloaderv1.FakeKoffloaderV1{Fake: &c.Fake} +// KoffloaderV1beta1 retrieves the KoffloaderV1beta1Client +func (c *Clientset) KoffloaderV1beta1() koffloaderv1beta1.KoffloaderV1beta1Interface { + return &fakekoffloaderv1beta1.FakeKoffloaderV1beta1{Fake: &c.Fake} } diff --git a/pkg/k8s/client/clientset/versioned/fake/register.go b/pkg/k8s/client/clientset/versioned/fake/register.go index 6d6918f7..8811f264 100644 --- a/pkg/k8s/client/clientset/versioned/fake/register.go +++ b/pkg/k8s/client/clientset/versioned/fake/register.go @@ -6,7 +6,7 @@ package fake import ( - koffloaderv1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" + koffloaderv1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -18,7 +18,7 @@ var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - koffloaderv1.AddToScheme, + koffloaderv1beta1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/k8s/client/clientset/versioned/scheme/register.go b/pkg/k8s/client/clientset/versioned/scheme/register.go index 93f302bd..c5f05129 100644 --- a/pkg/k8s/client/clientset/versioned/scheme/register.go +++ b/pkg/k8s/client/clientset/versioned/scheme/register.go @@ -6,7 +6,7 @@ package scheme import ( - koffloaderv1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" + koffloaderv1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -18,7 +18,7 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - koffloaderv1.AddToScheme, + koffloaderv1beta1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake/fake_kcluster.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake/fake_kcluster.go deleted file mode 100644 index e04724c9..00000000 --- a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake/fake_kcluster.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - - koffloaderkoffloaderiov1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" - 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" -) - -// FakeKclusters implements KclusterInterface -type FakeKclusters struct { - Fake *FakeKoffloaderV1 -} - -var kclustersResource = schema.GroupVersionResource{Group: "koffloader.koffloader.io", Version: "v1", Resource: "kclusters"} - -var kclustersKind = schema.GroupVersionKind{Group: "koffloader.koffloader.io", Version: "v1", Kind: "Kcluster"} - -// Get takes name of the kcluster, and returns the corresponding kcluster object, and an error if there is any. -func (c *FakeKclusters) Get(ctx context.Context, name string, options v1.GetOptions) (result *koffloaderkoffloaderiov1.Kcluster, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(kclustersResource, name), &koffloaderkoffloaderiov1.Kcluster{}) - if obj == nil { - return nil, err - } - return obj.(*koffloaderkoffloaderiov1.Kcluster), err -} - -// List takes label and field selectors, and returns the list of Kclusters that match those selectors. -func (c *FakeKclusters) List(ctx context.Context, opts v1.ListOptions) (result *koffloaderkoffloaderiov1.KclusterList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(kclustersResource, kclustersKind, opts), &koffloaderkoffloaderiov1.KclusterList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &koffloaderkoffloaderiov1.KclusterList{ListMeta: obj.(*koffloaderkoffloaderiov1.KclusterList).ListMeta} - for _, item := range obj.(*koffloaderkoffloaderiov1.KclusterList).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 kclusters. -func (c *FakeKclusters) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(kclustersResource, opts)) -} - -// Create takes the representation of a kcluster and creates it. Returns the server's representation of the kcluster, and an error, if there is any. -func (c *FakeKclusters) Create(ctx context.Context, kcluster *koffloaderkoffloaderiov1.Kcluster, opts v1.CreateOptions) (result *koffloaderkoffloaderiov1.Kcluster, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(kclustersResource, kcluster), &koffloaderkoffloaderiov1.Kcluster{}) - if obj == nil { - return nil, err - } - return obj.(*koffloaderkoffloaderiov1.Kcluster), err -} - -// Update takes the representation of a kcluster and updates it. Returns the server's representation of the kcluster, and an error, if there is any. -func (c *FakeKclusters) Update(ctx context.Context, kcluster *koffloaderkoffloaderiov1.Kcluster, opts v1.UpdateOptions) (result *koffloaderkoffloaderiov1.Kcluster, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(kclustersResource, kcluster), &koffloaderkoffloaderiov1.Kcluster{}) - if obj == nil { - return nil, err - } - return obj.(*koffloaderkoffloaderiov1.Kcluster), 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 *FakeKclusters) UpdateStatus(ctx context.Context, kcluster *koffloaderkoffloaderiov1.Kcluster, opts v1.UpdateOptions) (*koffloaderkoffloaderiov1.Kcluster, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(kclustersResource, "status", kcluster), &koffloaderkoffloaderiov1.Kcluster{}) - if obj == nil { - return nil, err - } - return obj.(*koffloaderkoffloaderiov1.Kcluster), err -} - -// Delete takes name of the kcluster and deletes it. Returns an error if one occurs. -func (c *FakeKclusters) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(kclustersResource, name, opts), &koffloaderkoffloaderiov1.Kcluster{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeKclusters) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(kclustersResource, listOpts) - - _, err := c.Fake.Invokes(action, &koffloaderkoffloaderiov1.KclusterList{}) - return err -} - -// Patch applies the patch and returns the patched kcluster. -func (c *FakeKclusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *koffloaderkoffloaderiov1.Kcluster, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(kclustersResource, name, pt, data, subresources...), &koffloaderkoffloaderiov1.Kcluster{}) - if obj == nil { - return nil, err - } - return obj.(*koffloaderkoffloaderiov1.Kcluster), err -} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake/fake_koffloader.koffloader.io_client.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake/fake_koffloader.koffloader.io_client.go deleted file mode 100644 index 37461e37..00000000 --- a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake/fake_koffloader.koffloader.io_client.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1 "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1" - rest "k8s.io/client-go/rest" - testing "k8s.io/client-go/testing" -) - -type FakeKoffloaderV1 struct { - *testing.Fake -} - -func (c *FakeKoffloaderV1) Kclusters() v1.KclusterInterface { - return &FakeKclusters{c} -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *FakeKoffloaderV1) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/generated_expansion.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/generated_expansion.go deleted file mode 100644 index 77ebe921..00000000 --- a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/generated_expansion.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -// Code generated by client-gen. DO NOT EDIT. - -package v1 - -type KclusterExpansion interface{} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/kcluster.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/kcluster.go deleted file mode 100644 index a8fb836e..00000000 --- a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/kcluster.go +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -// Code generated by client-gen. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - v1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" - scheme "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/scheme" - metav1 "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" -) - -// KclustersGetter has a method to return a KclusterInterface. -// A group's client should implement this interface. -type KclustersGetter interface { - Kclusters() KclusterInterface -} - -// KclusterInterface has methods to work with Kcluster resources. -type KclusterInterface interface { - Create(ctx context.Context, kcluster *v1.Kcluster, opts metav1.CreateOptions) (*v1.Kcluster, error) - Update(ctx context.Context, kcluster *v1.Kcluster, opts metav1.UpdateOptions) (*v1.Kcluster, error) - UpdateStatus(ctx context.Context, kcluster *v1.Kcluster, opts metav1.UpdateOptions) (*v1.Kcluster, error) - Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Kcluster, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.KclusterList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Kcluster, err error) - KclusterExpansion -} - -// kclusters implements KclusterInterface -type kclusters struct { - client rest.Interface -} - -// newKclusters returns a Kclusters -func newKclusters(c *KoffloaderV1Client) *kclusters { - return &kclusters{ - client: c.RESTClient(), - } -} - -// Get takes name of the kcluster, and returns the corresponding kcluster object, and an error if there is any. -func (c *kclusters) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Kcluster, err error) { - result = &v1.Kcluster{} - err = c.client.Get(). - Resource("kclusters"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Kclusters that match those selectors. -func (c *kclusters) List(ctx context.Context, opts metav1.ListOptions) (result *v1.KclusterList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.KclusterList{} - err = c.client.Get(). - Resource("kclusters"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested kclusters. -func (c *kclusters) Watch(ctx context.Context, opts metav1.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(). - Resource("kclusters"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a kcluster and creates it. Returns the server's representation of the kcluster, and an error, if there is any. -func (c *kclusters) Create(ctx context.Context, kcluster *v1.Kcluster, opts metav1.CreateOptions) (result *v1.Kcluster, err error) { - result = &v1.Kcluster{} - err = c.client.Post(). - Resource("kclusters"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(kcluster). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a kcluster and updates it. Returns the server's representation of the kcluster, and an error, if there is any. -func (c *kclusters) Update(ctx context.Context, kcluster *v1.Kcluster, opts metav1.UpdateOptions) (result *v1.Kcluster, err error) { - result = &v1.Kcluster{} - err = c.client.Put(). - Resource("kclusters"). - Name(kcluster.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(kcluster). - 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 *kclusters) UpdateStatus(ctx context.Context, kcluster *v1.Kcluster, opts metav1.UpdateOptions) (result *v1.Kcluster, err error) { - result = &v1.Kcluster{} - err = c.client.Put(). - Resource("kclusters"). - Name(kcluster.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(kcluster). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the kcluster and deletes it. Returns an error if one occurs. -func (c *kclusters) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Resource("kclusters"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *kclusters) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("kclusters"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched kcluster. -func (c *kclusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Kcluster, err error) { - result = &v1.Kcluster{} - err = c.client.Patch(pt). - Resource("kclusters"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/doc.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/doc.go similarity index 92% rename from pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/doc.go rename to pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/doc.go index 130f2e64..928dbb14 100644 --- a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/doc.go +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/doc.go @@ -4,4 +4,4 @@ // Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. -package v1 +package v1beta1 diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake/doc.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/doc.go similarity index 100% rename from pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/fake/doc.go rename to pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/doc.go diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_kcluster.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_kcluster.go new file mode 100644 index 00000000..f1f6d08b --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_kcluster.go @@ -0,0 +1,120 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + 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" +) + +// FakeKClusters implements KClusterInterface +type FakeKClusters struct { + Fake *FakeKoffloaderV1beta1 +} + +var kclustersResource = schema.GroupVersionResource{Group: "koffloader.koffloader.io", Version: "v1beta1", Resource: "kclusters"} + +var kclustersKind = schema.GroupVersionKind{Group: "koffloader.koffloader.io", Version: "v1beta1", Kind: "KCluster"} + +// Get takes name of the kCluster, and returns the corresponding kCluster object, and an error if there is any. +func (c *FakeKClusters) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.KCluster, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(kclustersResource, name), &v1beta1.KCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KCluster), err +} + +// List takes label and field selectors, and returns the list of KClusters that match those selectors. +func (c *FakeKClusters) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.KClusterList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(kclustersResource, kclustersKind, opts), &v1beta1.KClusterList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.KClusterList{ListMeta: obj.(*v1beta1.KClusterList).ListMeta} + for _, item := range obj.(*v1beta1.KClusterList).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 kClusters. +func (c *FakeKClusters) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(kclustersResource, opts)) +} + +// Create takes the representation of a kCluster and creates it. Returns the server's representation of the kCluster, and an error, if there is any. +func (c *FakeKClusters) Create(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.CreateOptions) (result *v1beta1.KCluster, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(kclustersResource, kCluster), &v1beta1.KCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KCluster), err +} + +// Update takes the representation of a kCluster and updates it. Returns the server's representation of the kCluster, and an error, if there is any. +func (c *FakeKClusters) Update(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.UpdateOptions) (result *v1beta1.KCluster, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(kclustersResource, kCluster), &v1beta1.KCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KCluster), 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 *FakeKClusters) UpdateStatus(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.UpdateOptions) (*v1beta1.KCluster, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(kclustersResource, "status", kCluster), &v1beta1.KCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KCluster), err +} + +// Delete takes name of the kCluster and deletes it. Returns an error if one occurs. +func (c *FakeKClusters) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(kclustersResource, name, opts), &v1beta1.KCluster{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeKClusters) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(kclustersResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.KClusterList{}) + return err +} + +// Patch applies the patch and returns the patched kCluster. +func (c *FakeKClusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.KCluster, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(kclustersResource, name, pt, data, subresources...), &v1beta1.KCluster{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KCluster), err +} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_kclustergroup.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_kclustergroup.go new file mode 100644 index 00000000..81da89e7 --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_kclustergroup.go @@ -0,0 +1,120 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + 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" +) + +// FakeKClusterGroups implements KClusterGroupInterface +type FakeKClusterGroups struct { + Fake *FakeKoffloaderV1beta1 +} + +var kclustergroupsResource = schema.GroupVersionResource{Group: "koffloader.koffloader.io", Version: "v1beta1", Resource: "kclustergroups"} + +var kclustergroupsKind = schema.GroupVersionKind{Group: "koffloader.koffloader.io", Version: "v1beta1", Kind: "KClusterGroup"} + +// Get takes name of the kClusterGroup, and returns the corresponding kClusterGroup object, and an error if there is any. +func (c *FakeKClusterGroups) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.KClusterGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(kclustergroupsResource, name), &v1beta1.KClusterGroup{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KClusterGroup), err +} + +// List takes label and field selectors, and returns the list of KClusterGroups that match those selectors. +func (c *FakeKClusterGroups) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.KClusterGroupList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(kclustergroupsResource, kclustergroupsKind, opts), &v1beta1.KClusterGroupList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.KClusterGroupList{ListMeta: obj.(*v1beta1.KClusterGroupList).ListMeta} + for _, item := range obj.(*v1beta1.KClusterGroupList).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 kClusterGroups. +func (c *FakeKClusterGroups) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(kclustergroupsResource, opts)) +} + +// Create takes the representation of a kClusterGroup and creates it. Returns the server's representation of the kClusterGroup, and an error, if there is any. +func (c *FakeKClusterGroups) Create(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.CreateOptions) (result *v1beta1.KClusterGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(kclustergroupsResource, kClusterGroup), &v1beta1.KClusterGroup{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KClusterGroup), err +} + +// Update takes the representation of a kClusterGroup and updates it. Returns the server's representation of the kClusterGroup, and an error, if there is any. +func (c *FakeKClusterGroups) Update(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.UpdateOptions) (result *v1beta1.KClusterGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(kclustergroupsResource, kClusterGroup), &v1beta1.KClusterGroup{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KClusterGroup), 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 *FakeKClusterGroups) UpdateStatus(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.UpdateOptions) (*v1beta1.KClusterGroup, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(kclustergroupsResource, "status", kClusterGroup), &v1beta1.KClusterGroup{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KClusterGroup), err +} + +// Delete takes name of the kClusterGroup and deletes it. Returns an error if one occurs. +func (c *FakeKClusterGroups) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(kclustergroupsResource, name, opts), &v1beta1.KClusterGroup{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeKClusterGroups) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(kclustergroupsResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.KClusterGroupList{}) + return err +} + +// Patch applies the patch and returns the patched kClusterGroup. +func (c *FakeKClusterGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.KClusterGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(kclustergroupsResource, name, pt, data, subresources...), &v1beta1.KClusterGroup{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KClusterGroup), err +} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_koffloader.koffloader.io_client.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_koffloader.koffloader.io_client.go new file mode 100644 index 00000000..5a641f4d --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_koffloader.koffloader.io_client.go @@ -0,0 +1,35 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeKoffloaderV1beta1 struct { + *testing.Fake +} + +func (c *FakeKoffloaderV1beta1) KClusters() v1beta1.KClusterInterface { + return &FakeKClusters{c} +} + +func (c *FakeKoffloaderV1beta1) KClusterGroups() v1beta1.KClusterGroupInterface { + return &FakeKClusterGroups{c} +} + +func (c *FakeKoffloaderV1beta1) ServiceExportPolicies() v1beta1.ServiceExportPolicyInterface { + return &FakeServiceExportPolicies{c} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeKoffloaderV1beta1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_serviceexportpolicy.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_serviceexportpolicy.go new file mode 100644 index 00000000..64c52c0c --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/fake/fake_serviceexportpolicy.go @@ -0,0 +1,120 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + 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" +) + +// FakeServiceExportPolicies implements ServiceExportPolicyInterface +type FakeServiceExportPolicies struct { + Fake *FakeKoffloaderV1beta1 +} + +var serviceexportpoliciesResource = schema.GroupVersionResource{Group: "koffloader.koffloader.io", Version: "v1beta1", Resource: "serviceexportpolicies"} + +var serviceexportpoliciesKind = schema.GroupVersionKind{Group: "koffloader.koffloader.io", Version: "v1beta1", Kind: "ServiceExportPolicy"} + +// Get takes name of the serviceExportPolicy, and returns the corresponding serviceExportPolicy object, and an error if there is any. +func (c *FakeServiceExportPolicies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ServiceExportPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(serviceexportpoliciesResource, name), &v1beta1.ServiceExportPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ServiceExportPolicy), err +} + +// List takes label and field selectors, and returns the list of ServiceExportPolicies that match those selectors. +func (c *FakeServiceExportPolicies) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ServiceExportPolicyList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(serviceexportpoliciesResource, serviceexportpoliciesKind, opts), &v1beta1.ServiceExportPolicyList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.ServiceExportPolicyList{ListMeta: obj.(*v1beta1.ServiceExportPolicyList).ListMeta} + for _, item := range obj.(*v1beta1.ServiceExportPolicyList).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 serviceExportPolicies. +func (c *FakeServiceExportPolicies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(serviceexportpoliciesResource, opts)) +} + +// Create takes the representation of a serviceExportPolicy and creates it. Returns the server's representation of the serviceExportPolicy, and an error, if there is any. +func (c *FakeServiceExportPolicies) Create(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.CreateOptions) (result *v1beta1.ServiceExportPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(serviceexportpoliciesResource, serviceExportPolicy), &v1beta1.ServiceExportPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ServiceExportPolicy), err +} + +// Update takes the representation of a serviceExportPolicy and updates it. Returns the server's representation of the serviceExportPolicy, and an error, if there is any. +func (c *FakeServiceExportPolicies) Update(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.UpdateOptions) (result *v1beta1.ServiceExportPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(serviceexportpoliciesResource, serviceExportPolicy), &v1beta1.ServiceExportPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ServiceExportPolicy), 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 *FakeServiceExportPolicies) UpdateStatus(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.UpdateOptions) (*v1beta1.ServiceExportPolicy, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(serviceexportpoliciesResource, "status", serviceExportPolicy), &v1beta1.ServiceExportPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ServiceExportPolicy), err +} + +// Delete takes name of the serviceExportPolicy and deletes it. Returns an error if one occurs. +func (c *FakeServiceExportPolicies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(serviceexportpoliciesResource, name, opts), &v1beta1.ServiceExportPolicy{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeServiceExportPolicies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(serviceexportpoliciesResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.ServiceExportPolicyList{}) + return err +} + +// Patch applies the patch and returns the patched serviceExportPolicy. +func (c *FakeServiceExportPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ServiceExportPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(serviceexportpoliciesResource, name, pt, data, subresources...), &v1beta1.ServiceExportPolicy{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ServiceExportPolicy), err +} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/generated_expansion.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/generated_expansion.go new file mode 100644 index 00000000..b56c483f --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/generated_expansion.go @@ -0,0 +1,12 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +type KClusterExpansion interface{} + +type KClusterGroupExpansion interface{} + +type ServiceExportPolicyExpansion interface{} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/kcluster.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/kcluster.go new file mode 100644 index 00000000..6865e6d8 --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/kcluster.go @@ -0,0 +1,171 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + scheme "github.com/koffloader-io/koffloader/pkg/k8s/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" +) + +// KClustersGetter has a method to return a KClusterInterface. +// A group's client should implement this interface. +type KClustersGetter interface { + KClusters() KClusterInterface +} + +// KClusterInterface has methods to work with KCluster resources. +type KClusterInterface interface { + Create(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.CreateOptions) (*v1beta1.KCluster, error) + Update(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.UpdateOptions) (*v1beta1.KCluster, error) + UpdateStatus(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.UpdateOptions) (*v1beta1.KCluster, 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) (*v1beta1.KCluster, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.KClusterList, 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 *v1beta1.KCluster, err error) + KClusterExpansion +} + +// kClusters implements KClusterInterface +type kClusters struct { + client rest.Interface +} + +// newKClusters returns a KClusters +func newKClusters(c *KoffloaderV1beta1Client) *kClusters { + return &kClusters{ + client: c.RESTClient(), + } +} + +// Get takes name of the kCluster, and returns the corresponding kCluster object, and an error if there is any. +func (c *kClusters) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.KCluster, err error) { + result = &v1beta1.KCluster{} + err = c.client.Get(). + Resource("kclusters"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of KClusters that match those selectors. +func (c *kClusters) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.KClusterList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.KClusterList{} + err = c.client.Get(). + Resource("kclusters"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested kClusters. +func (c *kClusters) 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(). + Resource("kclusters"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a kCluster and creates it. Returns the server's representation of the kCluster, and an error, if there is any. +func (c *kClusters) Create(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.CreateOptions) (result *v1beta1.KCluster, err error) { + result = &v1beta1.KCluster{} + err = c.client.Post(). + Resource("kclusters"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(kCluster). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a kCluster and updates it. Returns the server's representation of the kCluster, and an error, if there is any. +func (c *kClusters) Update(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.UpdateOptions) (result *v1beta1.KCluster, err error) { + result = &v1beta1.KCluster{} + err = c.client.Put(). + Resource("kclusters"). + Name(kCluster.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(kCluster). + 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 *kClusters) UpdateStatus(ctx context.Context, kCluster *v1beta1.KCluster, opts v1.UpdateOptions) (result *v1beta1.KCluster, err error) { + result = &v1beta1.KCluster{} + err = c.client.Put(). + Resource("kclusters"). + Name(kCluster.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(kCluster). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the kCluster and deletes it. Returns an error if one occurs. +func (c *kClusters) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("kclusters"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *kClusters) 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(). + Resource("kclusters"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched kCluster. +func (c *kClusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.KCluster, err error) { + result = &v1beta1.KCluster{} + err = c.client.Patch(pt). + Resource("kclusters"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/kclustergroup.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/kclustergroup.go new file mode 100644 index 00000000..35ffbf21 --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/kclustergroup.go @@ -0,0 +1,171 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + scheme "github.com/koffloader-io/koffloader/pkg/k8s/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" +) + +// KClusterGroupsGetter has a method to return a KClusterGroupInterface. +// A group's client should implement this interface. +type KClusterGroupsGetter interface { + KClusterGroups() KClusterGroupInterface +} + +// KClusterGroupInterface has methods to work with KClusterGroup resources. +type KClusterGroupInterface interface { + Create(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.CreateOptions) (*v1beta1.KClusterGroup, error) + Update(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.UpdateOptions) (*v1beta1.KClusterGroup, error) + UpdateStatus(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.UpdateOptions) (*v1beta1.KClusterGroup, 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) (*v1beta1.KClusterGroup, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.KClusterGroupList, 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 *v1beta1.KClusterGroup, err error) + KClusterGroupExpansion +} + +// kClusterGroups implements KClusterGroupInterface +type kClusterGroups struct { + client rest.Interface +} + +// newKClusterGroups returns a KClusterGroups +func newKClusterGroups(c *KoffloaderV1beta1Client) *kClusterGroups { + return &kClusterGroups{ + client: c.RESTClient(), + } +} + +// Get takes name of the kClusterGroup, and returns the corresponding kClusterGroup object, and an error if there is any. +func (c *kClusterGroups) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.KClusterGroup, err error) { + result = &v1beta1.KClusterGroup{} + err = c.client.Get(). + Resource("kclustergroups"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of KClusterGroups that match those selectors. +func (c *kClusterGroups) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.KClusterGroupList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.KClusterGroupList{} + err = c.client.Get(). + Resource("kclustergroups"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested kClusterGroups. +func (c *kClusterGroups) 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(). + Resource("kclustergroups"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a kClusterGroup and creates it. Returns the server's representation of the kClusterGroup, and an error, if there is any. +func (c *kClusterGroups) Create(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.CreateOptions) (result *v1beta1.KClusterGroup, err error) { + result = &v1beta1.KClusterGroup{} + err = c.client.Post(). + Resource("kclustergroups"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(kClusterGroup). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a kClusterGroup and updates it. Returns the server's representation of the kClusterGroup, and an error, if there is any. +func (c *kClusterGroups) Update(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.UpdateOptions) (result *v1beta1.KClusterGroup, err error) { + result = &v1beta1.KClusterGroup{} + err = c.client.Put(). + Resource("kclustergroups"). + Name(kClusterGroup.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(kClusterGroup). + 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 *kClusterGroups) UpdateStatus(ctx context.Context, kClusterGroup *v1beta1.KClusterGroup, opts v1.UpdateOptions) (result *v1beta1.KClusterGroup, err error) { + result = &v1beta1.KClusterGroup{} + err = c.client.Put(). + Resource("kclustergroups"). + Name(kClusterGroup.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(kClusterGroup). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the kClusterGroup and deletes it. Returns an error if one occurs. +func (c *kClusterGroups) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("kclustergroups"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *kClusterGroups) 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(). + Resource("kclustergroups"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched kClusterGroup. +func (c *kClusterGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.KClusterGroup, err error) { + result = &v1beta1.KClusterGroup{} + err = c.client.Patch(pt). + Resource("kclustergroups"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/koffloader.koffloader.io_client.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/koffloader.koffloader.io_client.go similarity index 52% rename from pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/koffloader.koffloader.io_client.go rename to pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/koffloader.koffloader.io_client.go index 7b97309a..aee20fd2 100644 --- a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1/koffloader.koffloader.io_client.go +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/koffloader.koffloader.io_client.go @@ -3,34 +3,44 @@ // Code generated by client-gen. DO NOT EDIT. -package v1 +package v1beta1 import ( "net/http" - v1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned/scheme" rest "k8s.io/client-go/rest" ) -type KoffloaderV1Interface interface { +type KoffloaderV1beta1Interface interface { RESTClient() rest.Interface - KclustersGetter + KClustersGetter + KClusterGroupsGetter + ServiceExportPoliciesGetter } -// KoffloaderV1Client is used to interact with features provided by the koffloader.koffloader.io group. -type KoffloaderV1Client struct { +// KoffloaderV1beta1Client is used to interact with features provided by the koffloader.koffloader.io group. +type KoffloaderV1beta1Client struct { restClient rest.Interface } -func (c *KoffloaderV1Client) Kclusters() KclusterInterface { - return newKclusters(c) +func (c *KoffloaderV1beta1Client) KClusters() KClusterInterface { + return newKClusters(c) } -// NewForConfig creates a new KoffloaderV1Client for the given config. +func (c *KoffloaderV1beta1Client) KClusterGroups() KClusterGroupInterface { + return newKClusterGroups(c) +} + +func (c *KoffloaderV1beta1Client) ServiceExportPolicies() ServiceExportPolicyInterface { + return newServiceExportPolicies(c) +} + +// NewForConfig creates a new KoffloaderV1beta1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). -func NewForConfig(c *rest.Config) (*KoffloaderV1Client, error) { +func NewForConfig(c *rest.Config) (*KoffloaderV1beta1Client, error) { config := *c if err := setConfigDefaults(&config); err != nil { return nil, err @@ -42,9 +52,9 @@ func NewForConfig(c *rest.Config) (*KoffloaderV1Client, error) { return NewForConfigAndClient(&config, httpClient) } -// NewForConfigAndClient creates a new KoffloaderV1Client for the given config and http client. +// NewForConfigAndClient creates a new KoffloaderV1beta1Client for the given config and http client. // Note the http client provided takes precedence over the configured transport values. -func NewForConfigAndClient(c *rest.Config, h *http.Client) (*KoffloaderV1Client, error) { +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*KoffloaderV1beta1Client, error) { config := *c if err := setConfigDefaults(&config); err != nil { return nil, err @@ -53,12 +63,12 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*KoffloaderV1Client, if err != nil { return nil, err } - return &KoffloaderV1Client{client}, nil + return &KoffloaderV1beta1Client{client}, nil } -// NewForConfigOrDie creates a new KoffloaderV1Client for the given config and +// NewForConfigOrDie creates a new KoffloaderV1beta1Client for the given config and // panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *KoffloaderV1Client { +func NewForConfigOrDie(c *rest.Config) *KoffloaderV1beta1Client { client, err := NewForConfig(c) if err != nil { panic(err) @@ -66,13 +76,13 @@ func NewForConfigOrDie(c *rest.Config) *KoffloaderV1Client { return client } -// New creates a new KoffloaderV1Client for the given RESTClient. -func New(c rest.Interface) *KoffloaderV1Client { - return &KoffloaderV1Client{c} +// New creates a new KoffloaderV1beta1Client for the given RESTClient. +func New(c rest.Interface) *KoffloaderV1beta1Client { + return &KoffloaderV1beta1Client{c} } func setConfigDefaults(config *rest.Config) error { - gv := v1.SchemeGroupVersion + gv := v1beta1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() @@ -86,7 +96,7 @@ func setConfigDefaults(config *rest.Config) error { // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. -func (c *KoffloaderV1Client) RESTClient() rest.Interface { +func (c *KoffloaderV1beta1Client) RESTClient() rest.Interface { if c == nil { return nil } diff --git a/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go new file mode 100644 index 00000000..4c1709a9 --- /dev/null +++ b/pkg/k8s/client/clientset/versioned/typed/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go @@ -0,0 +1,171 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + scheme "github.com/koffloader-io/koffloader/pkg/k8s/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" +) + +// ServiceExportPoliciesGetter has a method to return a ServiceExportPolicyInterface. +// A group's client should implement this interface. +type ServiceExportPoliciesGetter interface { + ServiceExportPolicies() ServiceExportPolicyInterface +} + +// ServiceExportPolicyInterface has methods to work with ServiceExportPolicy resources. +type ServiceExportPolicyInterface interface { + Create(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.CreateOptions) (*v1beta1.ServiceExportPolicy, error) + Update(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.UpdateOptions) (*v1beta1.ServiceExportPolicy, error) + UpdateStatus(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.UpdateOptions) (*v1beta1.ServiceExportPolicy, 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) (*v1beta1.ServiceExportPolicy, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.ServiceExportPolicyList, 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 *v1beta1.ServiceExportPolicy, err error) + ServiceExportPolicyExpansion +} + +// serviceExportPolicies implements ServiceExportPolicyInterface +type serviceExportPolicies struct { + client rest.Interface +} + +// newServiceExportPolicies returns a ServiceExportPolicies +func newServiceExportPolicies(c *KoffloaderV1beta1Client) *serviceExportPolicies { + return &serviceExportPolicies{ + client: c.RESTClient(), + } +} + +// Get takes name of the serviceExportPolicy, and returns the corresponding serviceExportPolicy object, and an error if there is any. +func (c *serviceExportPolicies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ServiceExportPolicy, err error) { + result = &v1beta1.ServiceExportPolicy{} + err = c.client.Get(). + Resource("serviceexportpolicies"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of ServiceExportPolicies that match those selectors. +func (c *serviceExportPolicies) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ServiceExportPolicyList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.ServiceExportPolicyList{} + err = c.client.Get(). + Resource("serviceexportpolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested serviceExportPolicies. +func (c *serviceExportPolicies) 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(). + Resource("serviceexportpolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a serviceExportPolicy and creates it. Returns the server's representation of the serviceExportPolicy, and an error, if there is any. +func (c *serviceExportPolicies) Create(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.CreateOptions) (result *v1beta1.ServiceExportPolicy, err error) { + result = &v1beta1.ServiceExportPolicy{} + err = c.client.Post(). + Resource("serviceexportpolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(serviceExportPolicy). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a serviceExportPolicy and updates it. Returns the server's representation of the serviceExportPolicy, and an error, if there is any. +func (c *serviceExportPolicies) Update(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.UpdateOptions) (result *v1beta1.ServiceExportPolicy, err error) { + result = &v1beta1.ServiceExportPolicy{} + err = c.client.Put(). + Resource("serviceexportpolicies"). + Name(serviceExportPolicy.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(serviceExportPolicy). + 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 *serviceExportPolicies) UpdateStatus(ctx context.Context, serviceExportPolicy *v1beta1.ServiceExportPolicy, opts v1.UpdateOptions) (result *v1beta1.ServiceExportPolicy, err error) { + result = &v1beta1.ServiceExportPolicy{} + err = c.client.Put(). + Resource("serviceexportpolicies"). + Name(serviceExportPolicy.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(serviceExportPolicy). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the serviceExportPolicy and deletes it. Returns an error if one occurs. +func (c *serviceExportPolicies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("serviceexportpolicies"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *serviceExportPolicies) 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(). + Resource("serviceexportpolicies"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched serviceExportPolicy. +func (c *serviceExportPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ServiceExportPolicy, err error) { + result = &v1beta1.ServiceExportPolicy{} + err = c.client.Patch(pt). + Resource("serviceexportpolicies"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/k8s/client/informers/externalversions/generic.go b/pkg/k8s/client/informers/externalversions/generic.go index ff4fbe6c..9c8c2ad3 100644 --- a/pkg/k8s/client/informers/externalversions/generic.go +++ b/pkg/k8s/client/informers/externalversions/generic.go @@ -8,7 +8,7 @@ package externalversions import ( "fmt" - v1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" ) @@ -39,9 +39,13 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=koffloader.koffloader.io, Version=v1 - case v1.SchemeGroupVersion.WithResource("kclusters"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Koffloader().V1().Kclusters().Informer()}, nil + // Group=koffloader.koffloader.io, Version=v1beta1 + case v1beta1.SchemeGroupVersion.WithResource("kclusters"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Koffloader().V1beta1().KClusters().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("kclustergroups"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Koffloader().V1beta1().KClusterGroups().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("serviceexportpolicies"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Koffloader().V1beta1().ServiceExportPolicies().Informer()}, nil } diff --git a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/interface.go b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/interface.go index 02c4c8ca..41faf668 100644 --- a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/interface.go +++ b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/interface.go @@ -7,13 +7,13 @@ package koffloader import ( internalinterfaces "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions/internalinterfaces" - v1 "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1" + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1" ) // Interface provides access to each of this group's versions. type Interface interface { - // V1 provides access to shared informers for resources in V1. - V1() v1.Interface + // V1beta1 provides access to shared informers for resources in V1beta1. + V1beta1() v1beta1.Interface } type group struct { @@ -27,7 +27,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// V1 returns a new v1.Interface. -func (g *group) V1() v1.Interface { - return v1.New(g.factory, g.namespace, g.tweakListOptions) +// V1beta1 returns a new v1beta1.Interface. +func (g *group) V1beta1() v1beta1.Interface { + return v1beta1.New(g.factory, g.namespace, g.tweakListOptions) } diff --git a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1/interface.go b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1/interface.go deleted file mode 100644 index babe38d4..00000000 --- a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1/interface.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -// Code generated by informer-gen. DO NOT EDIT. - -package v1 - -import ( - internalinterfaces "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // Kclusters returns a KclusterInformer. - Kclusters() KclusterInformer -} - -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} -} - -// Kclusters returns a KclusterInformer. -func (v *version) Kclusters() KclusterInformer { - return &kclusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/interface.go b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/interface.go new file mode 100644 index 00000000..114757cf --- /dev/null +++ b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/interface.go @@ -0,0 +1,46 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + internalinterfaces "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // KClusters returns a KClusterInformer. + KClusters() KClusterInformer + // KClusterGroups returns a KClusterGroupInformer. + KClusterGroups() KClusterGroupInformer + // ServiceExportPolicies returns a ServiceExportPolicyInformer. + ServiceExportPolicies() ServiceExportPolicyInformer +} + +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} +} + +// KClusters returns a KClusterInformer. +func (v *version) KClusters() KClusterInformer { + return &kClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// KClusterGroups returns a KClusterGroupInformer. +func (v *version) KClusterGroups() KClusterGroupInformer { + return &kClusterGroupInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// ServiceExportPolicies returns a ServiceExportPolicyInformer. +func (v *version) ServiceExportPolicies() ServiceExportPolicyInformer { + return &serviceExportPolicyInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1/kcluster.go b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/kcluster.go similarity index 52% rename from pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1/kcluster.go rename to pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/kcluster.go index fbe0aee5..f8eeec84 100644 --- a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1/kcluster.go +++ b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/kcluster.go @@ -3,74 +3,74 @@ // Code generated by informer-gen. DO NOT EDIT. -package v1 +package v1beta1 import ( "context" time "time" - koffloaderkoffloaderiov1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" + koffloaderkoffloaderiov1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" versioned "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned" internalinterfaces "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions/internalinterfaces" - v1 "github.com/koffloader-io/koffloader/pkg/k8s/client/listers/koffloader.koffloader.io/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1" + 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" ) -// KclusterInformer provides access to a shared informer and lister for -// Kclusters. -type KclusterInformer interface { +// KClusterInformer provides access to a shared informer and lister for +// KClusters. +type KClusterInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.KclusterLister + Lister() v1beta1.KClusterLister } -type kclusterInformer struct { +type kClusterInformer struct { factory internalinterfaces.SharedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc } -// NewKclusterInformer constructs a new informer for Kcluster type. +// NewKClusterInformer constructs a new informer for KCluster 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 NewKclusterInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredKclusterInformer(client, resyncPeriod, indexers, nil) +func NewKClusterInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredKClusterInformer(client, resyncPeriod, indexers, nil) } -// NewFilteredKclusterInformer constructs a new informer for Kcluster type. +// NewFilteredKClusterInformer constructs a new informer for KCluster 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 NewFilteredKclusterInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredKClusterInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KoffloaderV1().Kclusters().List(context.TODO(), options) + return client.KoffloaderV1beta1().KClusters().List(context.TODO(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KoffloaderV1().Kclusters().Watch(context.TODO(), options) + return client.KoffloaderV1beta1().KClusters().Watch(context.TODO(), options) }, }, - &koffloaderkoffloaderiov1.Kcluster{}, + &koffloaderkoffloaderiov1beta1.KCluster{}, resyncPeriod, indexers, ) } -func (f *kclusterInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredKclusterInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +func (f *kClusterInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredKClusterInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) } -func (f *kclusterInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&koffloaderkoffloaderiov1.Kcluster{}, f.defaultInformer) +func (f *kClusterInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&koffloaderkoffloaderiov1beta1.KCluster{}, f.defaultInformer) } -func (f *kclusterInformer) Lister() v1.KclusterLister { - return v1.NewKclusterLister(f.Informer().GetIndexer()) +func (f *kClusterInformer) Lister() v1beta1.KClusterLister { + return v1beta1.NewKClusterLister(f.Informer().GetIndexer()) } diff --git a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/kclustergroup.go b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/kclustergroup.go new file mode 100644 index 00000000..e194764c --- /dev/null +++ b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/kclustergroup.go @@ -0,0 +1,76 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + time "time" + + koffloaderkoffloaderiov1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + versioned "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned" + internalinterfaces "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions/internalinterfaces" + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1" + 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" +) + +// KClusterGroupInformer provides access to a shared informer and lister for +// KClusterGroups. +type KClusterGroupInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.KClusterGroupLister +} + +type kClusterGroupInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewKClusterGroupInformer constructs a new informer for KClusterGroup 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 NewKClusterGroupInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredKClusterGroupInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredKClusterGroupInformer constructs a new informer for KClusterGroup 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 NewFilteredKClusterGroupInformer(client versioned.Interface, 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.KoffloaderV1beta1().KClusterGroups().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KoffloaderV1beta1().KClusterGroups().Watch(context.TODO(), options) + }, + }, + &koffloaderkoffloaderiov1beta1.KClusterGroup{}, + resyncPeriod, + indexers, + ) +} + +func (f *kClusterGroupInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredKClusterGroupInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *kClusterGroupInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&koffloaderkoffloaderiov1beta1.KClusterGroup{}, f.defaultInformer) +} + +func (f *kClusterGroupInformer) Lister() v1beta1.KClusterGroupLister { + return v1beta1.NewKClusterGroupLister(f.Informer().GetIndexer()) +} diff --git a/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go new file mode 100644 index 00000000..4921401e --- /dev/null +++ b/pkg/k8s/client/informers/externalversions/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go @@ -0,0 +1,76 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + time "time" + + koffloaderkoffloaderiov1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + versioned "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned" + internalinterfaces "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions/internalinterfaces" + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1" + 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" +) + +// ServiceExportPolicyInformer provides access to a shared informer and lister for +// ServiceExportPolicies. +type ServiceExportPolicyInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.ServiceExportPolicyLister +} + +type serviceExportPolicyInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewServiceExportPolicyInformer constructs a new informer for ServiceExportPolicy 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 NewServiceExportPolicyInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredServiceExportPolicyInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredServiceExportPolicyInformer constructs a new informer for ServiceExportPolicy 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 NewFilteredServiceExportPolicyInformer(client versioned.Interface, 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.KoffloaderV1beta1().ServiceExportPolicies().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KoffloaderV1beta1().ServiceExportPolicies().Watch(context.TODO(), options) + }, + }, + &koffloaderkoffloaderiov1beta1.ServiceExportPolicy{}, + resyncPeriod, + indexers, + ) +} + +func (f *serviceExportPolicyInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredServiceExportPolicyInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *serviceExportPolicyInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&koffloaderkoffloaderiov1beta1.ServiceExportPolicy{}, f.defaultInformer) +} + +func (f *serviceExportPolicyInformer) Lister() v1beta1.ServiceExportPolicyLister { + return v1beta1.NewServiceExportPolicyLister(f.Informer().GetIndexer()) +} diff --git a/pkg/k8s/client/listers/koffloader.koffloader.io/v1/expansion_generated.go b/pkg/k8s/client/listers/koffloader.koffloader.io/v1/expansion_generated.go deleted file mode 100644 index a5996393..00000000 --- a/pkg/k8s/client/listers/koffloader.koffloader.io/v1/expansion_generated.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -// Code generated by lister-gen. DO NOT EDIT. - -package v1 - -// KclusterListerExpansion allows custom methods to be added to -// KclusterLister. -type KclusterListerExpansion interface{} diff --git a/pkg/k8s/client/listers/koffloader.koffloader.io/v1/kcluster.go b/pkg/k8s/client/listers/koffloader.koffloader.io/v1/kcluster.go deleted file mode 100644 index c80823ae..00000000 --- a/pkg/k8s/client/listers/koffloader.koffloader.io/v1/kcluster.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -// Code generated by lister-gen. DO NOT EDIT. - -package v1 - -import ( - v1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// KclusterLister helps list Kclusters. -// All objects returned here must be treated as read-only. -type KclusterLister interface { - // List lists all Kclusters in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.Kcluster, err error) - // Get retrieves the Kcluster from the index for a given name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1.Kcluster, error) - KclusterListerExpansion -} - -// kclusterLister implements the KclusterLister interface. -type kclusterLister struct { - indexer cache.Indexer -} - -// NewKclusterLister returns a new KclusterLister. -func NewKclusterLister(indexer cache.Indexer) KclusterLister { - return &kclusterLister{indexer: indexer} -} - -// List lists all Kclusters in the indexer. -func (s *kclusterLister) List(selector labels.Selector) (ret []*v1.Kcluster, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Kcluster)) - }) - return ret, err -} - -// Get retrieves the Kcluster from the index for a given name. -func (s *kclusterLister) Get(name string) (*v1.Kcluster, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("kcluster"), name) - } - return obj.(*v1.Kcluster), nil -} diff --git a/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/expansion_generated.go b/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/expansion_generated.go new file mode 100644 index 00000000..a487e611 --- /dev/null +++ b/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/expansion_generated.go @@ -0,0 +1,18 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +// KClusterListerExpansion allows custom methods to be added to +// KClusterLister. +type KClusterListerExpansion interface{} + +// KClusterGroupListerExpansion allows custom methods to be added to +// KClusterGroupLister. +type KClusterGroupListerExpansion interface{} + +// ServiceExportPolicyListerExpansion allows custom methods to be added to +// ServiceExportPolicyLister. +type ServiceExportPolicyListerExpansion interface{} diff --git a/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/kcluster.go b/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/kcluster.go new file mode 100644 index 00000000..b49fc143 --- /dev/null +++ b/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/kcluster.go @@ -0,0 +1,55 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// KClusterLister helps list KClusters. +// All objects returned here must be treated as read-only. +type KClusterLister interface { + // List lists all KClusters in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.KCluster, err error) + // Get retrieves the KCluster from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.KCluster, error) + KClusterListerExpansion +} + +// kClusterLister implements the KClusterLister interface. +type kClusterLister struct { + indexer cache.Indexer +} + +// NewKClusterLister returns a new KClusterLister. +func NewKClusterLister(indexer cache.Indexer) KClusterLister { + return &kClusterLister{indexer: indexer} +} + +// List lists all KClusters in the indexer. +func (s *kClusterLister) List(selector labels.Selector) (ret []*v1beta1.KCluster, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.KCluster)) + }) + return ret, err +} + +// Get retrieves the KCluster from the index for a given name. +func (s *kClusterLister) Get(name string) (*v1beta1.KCluster, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("kcluster"), name) + } + return obj.(*v1beta1.KCluster), nil +} diff --git a/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/kclustergroup.go b/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/kclustergroup.go new file mode 100644 index 00000000..616e6586 --- /dev/null +++ b/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/kclustergroup.go @@ -0,0 +1,55 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// KClusterGroupLister helps list KClusterGroups. +// All objects returned here must be treated as read-only. +type KClusterGroupLister interface { + // List lists all KClusterGroups in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.KClusterGroup, err error) + // Get retrieves the KClusterGroup from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.KClusterGroup, error) + KClusterGroupListerExpansion +} + +// kClusterGroupLister implements the KClusterGroupLister interface. +type kClusterGroupLister struct { + indexer cache.Indexer +} + +// NewKClusterGroupLister returns a new KClusterGroupLister. +func NewKClusterGroupLister(indexer cache.Indexer) KClusterGroupLister { + return &kClusterGroupLister{indexer: indexer} +} + +// List lists all KClusterGroups in the indexer. +func (s *kClusterGroupLister) List(selector labels.Selector) (ret []*v1beta1.KClusterGroup, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.KClusterGroup)) + }) + return ret, err +} + +// Get retrieves the KClusterGroup from the index for a given name. +func (s *kClusterGroupLister) Get(name string) (*v1beta1.KClusterGroup, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("kclustergroup"), name) + } + return obj.(*v1beta1.KClusterGroup), nil +} diff --git a/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go b/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go new file mode 100644 index 00000000..89ab6d8d --- /dev/null +++ b/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1/serviceexportpolicy.go @@ -0,0 +1,55 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1beta1 "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// ServiceExportPolicyLister helps list ServiceExportPolicies. +// All objects returned here must be treated as read-only. +type ServiceExportPolicyLister interface { + // List lists all ServiceExportPolicies in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.ServiceExportPolicy, err error) + // Get retrieves the ServiceExportPolicy from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.ServiceExportPolicy, error) + ServiceExportPolicyListerExpansion +} + +// serviceExportPolicyLister implements the ServiceExportPolicyLister interface. +type serviceExportPolicyLister struct { + indexer cache.Indexer +} + +// NewServiceExportPolicyLister returns a new ServiceExportPolicyLister. +func NewServiceExportPolicyLister(indexer cache.Indexer) ServiceExportPolicyLister { + return &serviceExportPolicyLister{indexer: indexer} +} + +// List lists all ServiceExportPolicies in the indexer. +func (s *serviceExportPolicyLister) List(selector labels.Selector) (ret []*v1beta1.ServiceExportPolicy, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.ServiceExportPolicy)) + }) + return ret, err +} + +// Get retrieves the ServiceExportPolicy from the index for a given name. +func (s *serviceExportPolicyLister) Get(name string) (*v1beta1.ServiceExportPolicy, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("serviceexportpolicy"), name) + } + return obj.(*v1beta1.ServiceExportPolicy), nil +} diff --git a/pkg/kclusterManager/controller.go b/pkg/kclusterManager/controller.go deleted file mode 100644 index 765e4f16..00000000 --- a/pkg/kclusterManager/controller.go +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -package kclusterManager - -import ( - "context" - "fmt" - "github.com/koffloader-io/koffloader/pkg/k8s" - crd "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" - crdclientset "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned" - "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions" - crdlisterv1 "github.com/koffloader-io/koffloader/pkg/k8s/client/listers/koffloader.koffloader.io/v1" - "github.com/koffloader-io/koffloader/pkg/lease" - "go.uber.org/zap" - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/cache" - "k8s.io/client-go/tools/record" - "k8s.io/client-go/util/workqueue" - "time" -) - -const ( - workerNumber = 2 - queueMaxRetries = 100 -) - -type informerHandler struct { - logger *zap.Logger - leaseName string - leaseNameSpace string - leaseId string - eventRecord record.EventRecorder - queue workqueue.RateLimitingInterface - crdlister crdlisterv1.KclusterLister - k8sclient crdclientset.Interface -} - -func (s *informerHandler) worker(ctx context.Context) { - for s.processNextWorkItem(ctx) { - } -} - -func (s *informerHandler) processNextWorkItem(ctx context.Context) bool { - key, quit := s.queue.Get() - if quit { - return false - } - defer s.queue.Done(key) - - err := s.syncHandler(ctx, key.(*crd.Kcluster)) - if err == nil { - s.queue.Forget(key) - } else { - s.logger.Sugar().Warnf("worker failed , error=%v", err) - if apierrors.IsConflict(err) { - // 更新CRD 时,resourceVersion 冲突,重试 - s.queue.AddRateLimited(key) - } else if s.queue.NumRequeues(key) < queueMaxRetries { - s.queue.AddRateLimited(key) - } - } - // handle nex item - return true -} - -// =================================== - -func (s *informerHandler) informerAddHandler(obj interface{}) { - - r, ok := obj.(*crd.Kcluster) - if !ok { - s.logger.Sugar().Errorf("failed to get crd: %+v", obj) - return - } - s.logger.Sugar().Infof("add kcluster : %+v", r) - - // enqueue - s.queue.AddRateLimited(r) - - // 基于工作队列,生产者和消费者模型,使得事件能够本可靠的 异步执行 成功 - // 例如 resourceVersion、断网等失败,最终都能够不断重试而手工 - s.eventRecord.Eventf(r, corev1.EventTypeNormal, "newKcluster", "crd event, new kcluster %v", r.Name) - -} - -func (s *informerHandler) informerUpdateHandler(oldObj interface{}, newObj interface{}) { - _, ok := oldObj.(*crd.Kcluster) - if !ok { - s.logger.Sugar().Errorf("failed to get crd: %+v", oldObj) - return - } - newone, ok := newObj.(*crd.Kcluster) - if !ok { - s.logger.Sugar().Errorf("failed to get crd: %+v", newObj) - return - } - s.logger.Sugar().Infof("update crd: %v", newone.Name) - - // // 简单方式处理事件,堵塞执行,重建重试5次更新, - // // 好处是代码简单,坏处是,resourceVersion、断网等场景,可能最终5次失败而最终失败 - // if !reflect.DeepEqual(curPod.Spec, oldPod.Spec) { - // // when errors.IsConflict owing to resourceVersion, auto retry 5 times at interval 10ms - // err := retry.RetryOnConflict(retry.DefaultRetry, func() error { - // return s.handleCrdEvent(context.Background(), curPod) - // }) - // if err != nil { - // s.logger.Sugar().Errorf("failed to update kcluster status, error=%v", err) - // } - // } -} - -func (s *informerHandler) informerDeleteHandler(obj interface{}) { - r, ok := obj.(*crd.Kcluster) - if !ok { - s.logger.Sugar().Errorf("failed to get crd: %+v", obj) - return - } - s.logger.Sugar().Infof("delete crd: %v", r.Name) -} - -// =================================== - -func (s *informerHandler) executeInformer() { - - // ------- client set - config, err := rest.InClusterConfig() - if err != nil { - s.logger.Sugar().Fatalf("failed to InClusterConfig, reason=%v", err) - } - clientset, err := crdclientset.NewForConfig(config) // 初始化 client - if err != nil { - s.logger.Sugar().Fatalf("failed to NewForConfig, reason=%v", err) - } - s.k8sclient = clientset - - ctx, cancel := context.WithCancel(context.Background()) - - if len(s.leaseName) > 0 && len(s.leaseNameSpace) > 0 && len(s.leaseId) > 0 { - s.logger.Sugar().Infof("%v try to get lease %s/%s to run informer", s.leaseId, s.leaseNameSpace, s.leaseName) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - rlogger := s.logger.Named(fmt.Sprintf("lease %s/%s", s.leaseNameSpace, s.leaseName)) - // id := globalConfig.PodName - getLease, lossLease, err := lease.NewLeaseElector(ctx, s.leaseNameSpace, s.leaseName, s.leaseId, rlogger) - if err != nil { - s.logger.Sugar().Fatalf("failed to generate lease, reason=%v ", err) - } - <-getLease - s.logger.Sugar().Infof("succeed to get lease %s/%s to run informer", s.leaseNameSpace, s.leaseName) - - go func(lossLease chan struct{}) { - <-lossLease - cancel() - s.logger.Sugar().Warnf("lease %s/%s is loss, informer is broken", s.leaseNameSpace, s.leaseName) - }(lossLease) - } - - // setup informer - s.logger.Info("begin to setup informer") - factory := externalversions.NewSharedInformerFactory(clientset, 0) - // 注意,一个 factory 下 对同一种 CRD 不能 创建 多个Informer,不然会 数据竞争 问题。 而 一个 factory 下, 可对不同 CRD 产生 各种的 Informer - - t := factory.Koffloader().V1().Kclusters() - s.crdlister = t.Lister() - - inform := t.Informer() - - // 在一个 Handler 逻辑中,是顺序消费所有的 crd 事件的 - // 简单说:有2个 crd add 事件,那么,先会调用 informerAddHandler 完成 事件1 后,才会 调用 informerAddHandler 处理 事件2 - inform.AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: s.informerAddHandler, - UpdateFunc: s.informerUpdateHandler, - DeleteFunc: s.informerDeleteHandler, - }) - - // 一个 inform 下 如果注册 第二套 AddEventHandler,那么,对于同一个 事件,两套 handler 是 使用 独立协程 并发调用的 . - // 这样,就能实现对同一个事件 并发调用不同的回调,好处是,他们底层是基于同一个 NewSharedInformer , 共用一个cache,能降低api server 之间的数据同步 - inform.AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: s.informerAddHandler, - UpdateFunc: s.informerUpdateHandler, - DeleteFunc: s.informerDeleteHandler, - }) - - defer s.queue.ShutDown() - go func() { - s.logger.Info("start worker") - - if !cache.WaitForNamedCacheSync("kcluster-controller", ctx.Done(), inform.HasSynced) { - s.logger.Error("failed to sync cache") - cancel() - return - } - - for i := 0; i < workerNumber; i++ { - go wait.UntilWithContext(ctx, s.worker, time.Second) - } - }() - - inform.Run(ctx.Done()) - -} - -func (s *kclusterManager) RunController(leaseName, leaseNameSpace string, leaseId string) { - - scheme, e := crd.SchemeBuilder.Build() - if e != nil { - s.logger.Sugar().Fatalf("failed to get crd scheme: %+v", e) - } - /* - Events: - Type Reason Age From Message - ---- ------ ---- ---- ------- - Normal newKcluster 13s kcluster crd event, new kcluster test - */ - p := k8s.NewEventRecord(scheme, "kcluster", s.logger) - - // ----------- - t := &informerHandler{ - logger: s.logger, - leaseName: leaseName, - leaseNameSpace: leaseNameSpace, - leaseId: leaseId, - eventRecord: p, - queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "kcluster"), - } - s.informer = t - - go func() { - for { - t.executeInformer() - time.Sleep(time.Duration(5) * time.Second) - } - }() -} diff --git a/pkg/kclusterManager/controller_worker.go b/pkg/kclusterManager/controller_worker.go deleted file mode 100644 index ab69f8e9..00000000 --- a/pkg/kclusterManager/controller_worker.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -package kclusterManager - -import ( - "context" - crd "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "reflect" -) - -func (s *informerHandler) syncHandler(ctx context.Context, obj *crd.Kcluster) error { - if obj == nil { - return nil - } - logger := s.logger.Named("worker") - - // 通过 clientset 向 api server 实时获取最新数据 - // old, err := s.k8sclient.koffloaderV1().Kclusters().Get(ctx, obj.Name, metav1.GetOptions{}) - // 获取最新cache中的数据(cache中的数据有延时风险) - old, err := s.crdlister.Get(obj.Name) - if err != nil { - logger.Warn("failed to get " + obj.Name) - if apierrors.IsNotFound(err) { - // not found ,no retry - return nil - } - // retry later - return err - } - logger.Info("handle " + obj.Name) - - newone := old.DeepCopy() - newone.Status.TotalIPCount = 100 - - if !reflect.DeepEqual(old, newone) { - if _, err := s.k8sclient.KoffloaderV1().Kclusters().UpdateStatus(ctx, newone, metav1.UpdateOptions{}); err != nil { - // if conflicted, queue will retry it later - return err - } - logger.Info("succeed to update " + obj.Name) - - // generate crd event - s.eventRecord.Eventf(newone, corev1.EventTypeNormal, "modified Kcluster", "crd event, new kcluster %v", newone.Name) - - } - - return nil -} diff --git a/pkg/kclusterManager/informer.go b/pkg/kclusterManager/informer.go new file mode 100644 index 00000000..2da7d1d8 --- /dev/null +++ b/pkg/kclusterManager/informer.go @@ -0,0 +1,224 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +package kclusterManager + +import ( + "context" + "fmt" + crd "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" + crdclientset "github.com/koffloader-io/koffloader/pkg/k8s/client/clientset/versioned" + "github.com/koffloader-io/koffloader/pkg/k8s/client/informers/externalversions" + crdlisterv1 "github.com/koffloader-io/koffloader/pkg/k8s/client/listers/koffloader.koffloader.io/v1beta1" + "github.com/koffloader-io/koffloader/pkg/lease" + "go.uber.org/zap" + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/tools/cache" + "k8s.io/client-go/tools/record" + "k8s.io/client-go/util/workqueue" + "reflect" + ctrl "sigs.k8s.io/controller-runtime" + "time" +) + +const ( + workerNumber = 2 + queueMaxRetries = 100 +) + +type KClusterInformer struct { + logger *zap.Logger + leaseName string + leaseNameSpace string + leaseId string + eventRecord record.EventRecorder + queue workqueue.RateLimitingInterface + kClusterLister crdlisterv1.KClusterLister + kClusterSynced cache.InformerSynced + crdClient crdclientset.Interface +} + +func NewKClusterInformer(logger *zap.Logger) *KClusterInformer { + crdClient, err := crdclientset.NewForConfig(ctrl.GetConfigOrDie()) + if err != nil { + logger.Fatal(err.Error()) + } + // todo[ii2day]: lease + kci := &KClusterInformer{ + logger: logger, + queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "kClusterInformer"), + crdClient: crdClient, + } + return kci +} + +func (s *KClusterInformer) worker(ctx context.Context) { + for s.processNextWorkItem(ctx) { + } +} + +func (s *KClusterInformer) processNextWorkItem(ctx context.Context) bool { + key, quit := s.queue.Get() + if quit { + return false + } + defer s.queue.Done(key) + + err := s.syncHandler(ctx, key.(*crd.KCluster)) + if err == nil { + s.queue.Forget(key) + } else { + s.logger.Sugar().Warnf("worker failed , error=%v", err) + if apierrors.IsConflict(err) { + // 更新CRD 时,resourceVersion 冲突,重试 + s.queue.AddRateLimited(key) + } else if s.queue.NumRequeues(key) < queueMaxRetries { + s.queue.AddRateLimited(key) + } + } + // handle nex item + return true +} + +// =================================== + +func (s *KClusterInformer) informerAddHandler(obj interface{}) { + + r, ok := obj.(*crd.KCluster) + if !ok { + s.logger.Sugar().Errorf("failed to get crd: %+v", obj) + return + } + s.logger.Sugar().Infof("add KCluster : %+v", r) + + // enqueue + s.queue.AddRateLimited(r) + +} + +func (s *KClusterInformer) informerUpdateHandler(oldObj interface{}, newObj interface{}) { + _, ok := oldObj.(*crd.KCluster) + if !ok { + s.logger.Sugar().Errorf("failed to get crd: %+v", oldObj) + return + } + newone, ok := newObj.(*crd.KCluster) + if !ok { + s.logger.Sugar().Errorf("failed to get crd: %+v", newObj) + return + } + s.logger.Sugar().Infof("update crd: %v", newone.Name) + + // // 简单方式处理事件,堵塞执行,重建重试5次更新, + // // 好处是代码简单,坏处是,resourceVersion、断网等场景,可能最终5次失败而最终失败 + // if !reflect.DeepEqual(curPod.Spec, oldPod.Spec) { + // // when errors.IsConflict owing to resourceVersion, auto retry 5 times at interval 10ms + // err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + // return s.handleCrdEvent(context.Background(), curPod) + // }) + // if err != nil { + // s.logger.Sugar().Errorf("failed to update KCluster status, error=%v", err) + // } + // } +} + +func (s *KClusterInformer) informerDeleteHandler(obj interface{}) { + r, ok := obj.(*crd.KCluster) + if !ok { + s.logger.Sugar().Errorf("failed to get crd: %+v", obj) + return + } + s.logger.Sugar().Infof("delete crd: %v", r.Name) +} + +// =================================== + +func (s *KClusterInformer) SetupInformer(ctx context.Context) { + s.logger.Info("begin to setup informer") + go func() { + if len(s.leaseName) > 0 && len(s.leaseNameSpace) > 0 && len(s.leaseId) > 0 { + s.logger.Sugar().Infof("%v try to get lease %s/%s to run informer", s.leaseId, s.leaseNameSpace, s.leaseName) + rlogger := s.logger.Named(fmt.Sprintf("lease %s/%s", s.leaseNameSpace, s.leaseName)) + // id := globalConfig.PodName + getLease, lossLease, err := lease.NewLeaseElector(ctx, s.leaseNameSpace, s.leaseName, s.leaseId, rlogger) + if err != nil { + s.logger.Sugar().Fatalf("failed to generate lease, reason=%v ", err) + } + <-getLease + s.logger.Sugar().Infof("succeed to get lease %s/%s to run informer", s.leaseNameSpace, s.leaseName) + + go func(lossLease chan struct{}) { + <-lossLease + s.logger.Sugar().Warnf("lease %s/%s is loss, informer is broken", s.leaseNameSpace, s.leaseName) + }(lossLease) + } + + // setup informer + factory := externalversions.NewSharedInformerFactory(s.crdClient, 0) + t := factory.Koffloader().V1beta1().KClusters() + s.kClusterLister = t.Lister() + t.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: s.informerAddHandler, + UpdateFunc: s.informerUpdateHandler, + DeleteFunc: s.informerDeleteHandler, + }) + s.kClusterSynced = t.Informer().HasSynced + factory.Start(ctx.Done()) + s.run(ctx) + }() +} + +func (s *KClusterInformer) run(ctx context.Context) { + defer utilruntime.HandleCrash() + defer s.queue.ShutDown() + + if ok := cache.WaitForCacheSync(ctx.Done(), s.kClusterSynced); !ok { + s.logger.Error("failed to sync cache") + return + } + // Launch two workers to process kcluster resources + for i := 0; i < workerNumber; i++ { + go wait.UntilWithContext(ctx, s.worker, time.Second) + } + <-ctx.Done() +} + +func (s *KClusterInformer) syncHandler(ctx context.Context, obj *crd.KCluster) error { + if obj == nil { + return nil + } + logger := s.logger.Named("worker") + + // 通过 clientset 向 api server 实时获取最新数据 + // old, err := s.k8sclient.koffloaderV1().Kclusters().Get(ctx, obj.Name, metav1.GetOptions{}) + // 获取最新cache中的数据(cache中的数据有延时风险) + old, err := s.kClusterLister.Get(obj.Name) + if err != nil { + logger.Warn("failed to get " + obj.Name) + if apierrors.IsNotFound(err) { + // not found ,no retry + return nil + } + // retry later + return err + } + logger.Info("handle " + obj.Name) + + newone := old.DeepCopy() + if !reflect.DeepEqual(old, newone) { + if _, err := s.crdClient.KoffloaderV1beta1().KClusters().UpdateStatus(ctx, newone, metav1.UpdateOptions{}); err != nil { + // if conflicted, queue will retry it later + return err + } + logger.Info("succeed to update " + obj.Name) + + // generate crd event + s.eventRecord.Eventf(newone, corev1.EventTypeNormal, "modified Kcluster", "crd event, new kcluster %v", newone.Name) + + } + return nil +} diff --git a/pkg/kclusterManager/manager.go b/pkg/kclusterManager/manager.go index fd8a9c59..d7081e02 100644 --- a/pkg/kclusterManager/manager.go +++ b/pkg/kclusterManager/manager.go @@ -2,23 +2,3 @@ // SPDX-License-Identifier: Apache-2.0 package kclusterManager - -import ( - "github.com/koffloader-io/koffloader/pkg/kclusterManager/types" - "go.uber.org/zap" -) - -type kclusterManager struct { - logger *zap.Logger - webhook *webhookhander - informer *informerHandler -} - -var _ types.KclusterManager = (*kclusterManager)(nil) - -func New(logger *zap.Logger) types.KclusterManager { - - return &kclusterManager{ - logger: logger.Named("kclusterManager"), - } -} diff --git a/pkg/kclusterManager/types/type.go b/pkg/kclusterManager/types/type.go deleted file mode 100644 index 871e1ce5..00000000 --- a/pkg/kclusterManager/types/type.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -package types - -type KclusterManager interface { - RunWebhookServer(webhookPort int, tlsDir string) - RunController(leaseName, leaseNameSpace string, leaseId string) -} diff --git a/pkg/kclusterManager/webhook.go b/pkg/kclusterManager/webhook.go index 122543ce..763c26df 100644 --- a/pkg/kclusterManager/webhook.go +++ b/pkg/kclusterManager/webhook.go @@ -5,76 +5,66 @@ package kclusterManager import ( "context" - "fmt" - crd "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1" + crd "github.com/koffloader-io/koffloader/pkg/k8s/apis/koffloader.koffloader.io/v1beta1" "go.uber.org/zap" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/webhook" - "time" ) // -------------------- -type webhookhander struct { - logger *zap.Logger +type KClusterWebHook struct { + Logger *zap.Logger } -var _ webhook.CustomValidator = (*webhookhander)(nil) +var _ webhook.CustomValidator = (*KClusterWebHook)(nil) // mutating webhook -func (s *webhookhander) Default(ctx context.Context, obj runtime.Object) error { - logger := s.logger.Named("mutating wehbook") +func (kw *KClusterWebHook) Default(ctx context.Context, obj runtime.Object) error { + logger := kw.Logger.Named("mutating wehbook") - r, ok := obj.(*crd.Kcluster) + r, ok := obj.(*crd.KCluster) if !ok { - s := "failed to get obj" - logger.Error(s) - return apierrors.NewBadRequest(s) + kw := "failed to get obj" + logger.Error(kw) + return apierrors.NewBadRequest(kw) } logger.Sugar().Infof("obj: %+v", r) - r.Annotations["test"] = "add-by-mutating-webhook" - - finalizerName := "koffloader.koffloader.io" - if dt := r.GetDeletionTimestamp(); dt.IsZero() && !controllerutil.ContainsFinalizer(client.Object(r), finalizerName) { - controllerutil.AddFinalizer(client.Object(r), finalizerName) - } return nil } -func (s *webhookhander) ValidateCreate(ctx context.Context, obj runtime.Object) error { - logger := s.logger.Named("validating create webhook") +func (kw *KClusterWebHook) ValidateCreate(ctx context.Context, obj runtime.Object) error { + logger := kw.Logger.Named("validating create webhook") - r, ok := obj.(*crd.Kcluster) + r, ok := obj.(*crd.KCluster) if !ok { - s := "failed to get obj" - logger.Error(s) - return apierrors.NewBadRequest(s) + kw := "failed to get obj" + logger.Error(kw) + return apierrors.NewBadRequest(kw) } logger.Sugar().Infof("obj: %+v", r) return nil } -func (s *webhookhander) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error { - logger := s.logger.Named("validating update webhook") +func (kw *KClusterWebHook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error { + logger := kw.Logger.Named("validating update webhook") - old, ok := oldObj.(*crd.Kcluster) + old, ok := oldObj.(*crd.KCluster) if !ok { - s := "failed to get oldObj" - logger.Error(s) - return apierrors.NewBadRequest(s) + kw := "failed to get oldObj" + logger.Error(kw) + return apierrors.NewBadRequest(kw) } - new, ok := newObj.(*crd.Kcluster) + new, ok := newObj.(*crd.KCluster) if !ok { - s := "failed to get newObj" - logger.Error(s) - return apierrors.NewBadRequest(s) + kw := "failed to get newObj" + logger.Error(kw) + return apierrors.NewBadRequest(kw) } logger.Sugar().Infof("oldObj: %+v", old) logger.Sugar().Infof("newObj: %+v", new) @@ -83,14 +73,14 @@ func (s *webhookhander) ValidateUpdate(ctx context.Context, oldObj, newObj runti } // ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type -func (s *webhookhander) ValidateDelete(ctx context.Context, obj runtime.Object) error { - logger := s.logger.Named("validating delete webhook") +func (kw *KClusterWebHook) ValidateDelete(ctx context.Context, obj runtime.Object) error { + logger := kw.Logger.Named("validating delete webhook") - r, ok := obj.(*crd.Kcluster) + r, ok := obj.(*crd.KCluster) if !ok { - s := "failed to get obj" - logger.Error(s) - return apierrors.NewBadRequest(s) + kw := "failed to get obj" + logger.Error(kw) + return apierrors.NewBadRequest(kw) } logger.Sugar().Infof("obj: %+v", r) @@ -99,55 +89,14 @@ func (s *webhookhander) ValidateDelete(ctx context.Context, obj runtime.Object) // -------------------- -// https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/builder/example_webhook_test.go -// https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/builder/webhook_test.go -func (s *kclusterManager) RunWebhookServer(webhookPort int, tlsDir string) { - logger := s.logger - r := &webhookhander{ - logger: logger, - } - s.webhook = r - - logger.Sugar().Infof("setup webhook on port %v, with tls under %v", webhookPort, tlsDir) - - scheme := runtime.NewScheme() - if e := crd.AddToScheme(scheme); e != nil { - logger.Sugar().Fatalf("failed to add crd scheme, reason=%v", e) - } - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ - Scheme: scheme, - LeaderElection: false, - MetricsBindAddress: "0", - HealthProbeBindAddress: "0", - // webhook port - Port: webhookPort, - // directory that contains the webhook server key and certificate, The server key and certificate must be named tls.key and tls.crt - CertDir: tlsDir, - }) - if err != nil { - logger.Sugar().Fatalf("failed to NewManager, reason=%v", err) - } - +func (kw *KClusterWebHook) SetupWebhookWithManager(mgr ctrl.Manager) { // the mutating route path : "/mutate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind) // the validate route path : "/validate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind) - e := ctrl.NewWebhookManagedBy(mgr). - For(&crd.Kcluster{}). - WithDefaulter(r). - WithValidator(r). - Complete() - if e != nil { - logger.Sugar().Fatalf("failed to NewWebhookManagedBy, reason=%v", e) + if e := ctrl.NewWebhookManagedBy(mgr). + For(&crd.KCluster{}). + WithDefaulter(kw). + WithValidator(kw). + Complete(); e != nil { + kw.Logger.Sugar().Fatalf("failed to NewWebhookManagedBy, reason=%v", e) } - - go func() { - s := "webhook down" - - // mgr.Start() - if err := mgr.GetWebhookServer().Start(context.Background()); err != nil { - s += fmt.Sprintf(", reason=%v", err) - } - logger.Error(s) - time.Sleep(time.Second) - }() - } diff --git a/pkg/types/const.go b/pkg/types/const.go index 29efa526..9670154e 100644 --- a/pkg/types/const.go +++ b/pkg/types/const.go @@ -3,5 +3,6 @@ package types const ( - TlsCaCommonName = "koffloader.io" + ControllerElectorLockName = "kdoctor-controller-lease" + TlsCaCommonName = "koffloader.io" ) diff --git a/test/Makefile b/test/Makefile index 0bec2c12..3c6ab388 100644 --- a/test/Makefile +++ b/test/Makefile @@ -246,8 +246,8 @@ install_example_app: @ KUBECONFIG=$(KIND_KUBECONFIG) kubectl get pod -o wide -A -.PHONY: clean_e2e -clean_e2e: +.PHONY: clean +clean: @rm -rf $(CLUSTER_DIR) -@ kind get clusters | xargs -n1 kind delete cluster --name -@ docker stop $(PYROSCOPE_CONTAINER_NAME) &>/dev/null diff --git a/tools/golang/crdControllerGen.sh b/tools/golang/crdControllerGen.sh index 688da02c..e084f996 100755 --- a/tools/golang/crdControllerGen.sh +++ b/tools/golang/crdControllerGen.sh @@ -13,7 +13,7 @@ set -o pipefail PROJECT_ROOT=$(dirname ${BASH_SOURCE[0]})/../.. CHART_DIR=${1:-"${PROJECT_ROOT}/charts"} -API_CODE_DIR=${2:-"${PROJECT_ROOT}/pkg/k8s/apis/koffloader.koffloader.io/v1"} +API_CODE_DIR=${2:-"${PROJECT_ROOT}/pkg/k8s/apis/koffloader.koffloader.io/v1beta1"} #====================== diff --git a/tools/golang/crdSdkGen.sh b/tools/golang/crdSdkGen.sh index 3e4c36f9..03a3e137 100755 --- a/tools/golang/crdSdkGen.sh +++ b/tools/golang/crdSdkGen.sh @@ -12,7 +12,7 @@ set -o pipefail APIS_PKG="pkg/k8s/apis" OUTPUT_PKG="pkg/k8s/client" -GROUPS_WITH_VERSIONS="koffloader.koffloader.io:v1" +GROUPS_WITH_VERSIONS="koffloader.koffloader.io:v1beta1" #===================