From 5b20b10fc2d8acf1988f17f0fead20ac3262bac7 Mon Sep 17 00:00:00 2001 From: Mridul Date: Tue, 19 Sep 2023 11:15:17 +0530 Subject: [PATCH] added slicegatewayServiceType field Signed-off-by: Mridul --- apis/controller/v1alpha1/sliceconfig_types.go | 10 +++++++++ .../v1alpha1/zz_generated.deepcopy.go | 22 ++++++++++++++++++- .../v1alpha1/workersliceconfig_types.go | 2 ++ .../controller.kubeslice.io_sliceconfigs.yaml | 12 ++++++++++ ...orker.kubeslice.io_workersliceconfigs.yaml | 5 +++++ service/kube_slice_resource_names.go | 7 +++--- service/worker_slice_config_service.go | 19 +++++++++++++++- 7 files changed, 72 insertions(+), 5 deletions(-) diff --git a/apis/controller/v1alpha1/sliceconfig_types.go b/apis/controller/v1alpha1/sliceconfig_types.go index e6b8e868..999a757a 100644 --- a/apis/controller/v1alpha1/sliceconfig_types.go +++ b/apis/controller/v1alpha1/sliceconfig_types.go @@ -74,6 +74,16 @@ type WorkerSliceGatewayProvider struct { //+kubebuilder:default:=Local // +kubebuilder:validation:Required SliceCaType string `json:"sliceCaType"` + + SliceGatewayServiceType []SliceGatewayServiceType `json:"sliceGatewayServiceType,omitempty"` +} + +type SliceGatewayServiceType struct { + // +kubebuilder:validation:Required + Cluster string `json:"cluster,omitempty"` + // +kubebuilder:validation:Required + //+kubebuilder:validation:Enum:=NodePort;LoadBalancer + Type string `json:"type,omitempty"` } // QOSProfile is the QOS Profile configuration from backend diff --git a/apis/controller/v1alpha1/zz_generated.deepcopy.go b/apis/controller/v1alpha1/zz_generated.deepcopy.go index 958b7b9c..5c3ebba4 100644 --- a/apis/controller/v1alpha1/zz_generated.deepcopy.go +++ b/apis/controller/v1alpha1/zz_generated.deepcopy.go @@ -674,7 +674,7 @@ func (in *SliceConfigList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SliceConfigSpec) DeepCopyInto(out *SliceConfigSpec) { *out = *in - out.SliceGatewayProvider = in.SliceGatewayProvider + in.SliceGatewayProvider.DeepCopyInto(&out.SliceGatewayProvider) if in.Clusters != nil { in, out := &in.Clusters, &out.Clusters *out = make([]string, len(*in)) @@ -736,6 +736,21 @@ func (in *SliceConfigStatus) DeepCopy() *SliceConfigStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SliceGatewayServiceType) DeepCopyInto(out *SliceGatewayServiceType) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SliceGatewayServiceType. +func (in *SliceGatewayServiceType) DeepCopy() *SliceGatewayServiceType { + if in == nil { + return nil + } + out := new(SliceGatewayServiceType) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SliceNamespaceSelection) DeepCopyInto(out *SliceNamespaceSelection) { *out = *in @@ -1051,6 +1066,11 @@ func (in *VpnKeyRotationStatus) DeepCopy() *VpnKeyRotationStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkerSliceGatewayProvider) DeepCopyInto(out *WorkerSliceGatewayProvider) { *out = *in + if in.SliceGatewayServiceType != nil { + in, out := &in.SliceGatewayServiceType, &out.SliceGatewayServiceType + *out = make([]SliceGatewayServiceType, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkerSliceGatewayProvider. diff --git a/apis/worker/v1alpha1/workersliceconfig_types.go b/apis/worker/v1alpha1/workersliceconfig_types.go index 5a99981c..531211ff 100644 --- a/apis/worker/v1alpha1/workersliceconfig_types.go +++ b/apis/worker/v1alpha1/workersliceconfig_types.go @@ -59,6 +59,8 @@ type WorkerSliceGatewayProvider struct { SliceGatewayType string `json:"sliceGatewayType,omitempty"` //+kubebuilder:default:=Local SliceCaType string `json:"sliceCaType,omitempty"` + //+kubebuilder:validation:Enum:=NodePort;LoadBalancer + SliceGatewayServiceType string `json:"sliceGatewayServiceType,omitempty"` } // QOSProfile is the QOS Profile configuration from backend diff --git a/config/crd/bases/controller.kubeslice.io_sliceconfigs.yaml b/config/crd/bases/controller.kubeslice.io_sliceconfigs.yaml index 4d297ef9..02ed58c4 100644 --- a/config/crd/bases/controller.kubeslice.io_sliceconfigs.yaml +++ b/config/crd/bases/controller.kubeslice.io_sliceconfigs.yaml @@ -159,6 +159,18 @@ spec: sliceCaType: default: Local type: string + sliceGatewayServiceType: + items: + properties: + cluster: + type: string + type: + enum: + - NodePort + - LoadBalancer + type: string + type: object + type: array sliceGatewayType: default: OpenVPN type: string diff --git a/config/crd/bases/worker.kubeslice.io_workersliceconfigs.yaml b/config/crd/bases/worker.kubeslice.io_workersliceconfigs.yaml index 916eb71b..1542d9b9 100644 --- a/config/crd/bases/worker.kubeslice.io_workersliceconfigs.yaml +++ b/config/crd/bases/worker.kubeslice.io_workersliceconfigs.yaml @@ -117,6 +117,11 @@ spec: sliceCaType: default: Local type: string + sliceGatewayServiceType: + enum: + - NodePort + - LoadBalancer + type: string sliceGatewayType: default: OpenVPN type: string diff --git a/service/kube_slice_resource_names.go b/service/kube_slice_resource_names.go index d567df97..03932de3 100644 --- a/service/kube_slice_resource_names.go +++ b/service/kube_slice_resource_names.go @@ -151,9 +151,10 @@ var ( ) const ( - serverGateway = "Server" - clientGateway = "Client" - workerSliceGatewayType = "OpenVPN" + serverGateway = "Server" + clientGateway = "Client" + workerSliceGatewayType = "OpenVPN" + defaultSliceGatewayServiceType = "NodePort" ) var ( diff --git a/service/worker_slice_config_service.go b/service/worker_slice_config_service.go index 19f30890..b914e881 100644 --- a/service/worker_slice_config_service.go +++ b/service/worker_slice_config_service.go @@ -19,9 +19,10 @@ package service import ( "context" "fmt" - "github.com/kubeslice/kubeslice-controller/metrics" "time" + "github.com/kubeslice/kubeslice-controller/metrics" + "github.com/kubeslice/kubeslice-controller/events" "go.uber.org/zap" @@ -211,6 +212,22 @@ outer: logger.With(zap.Error(err)).Errorf("Failed to deep copy external gateway configuration") } + // Reconcile Slice gateway service type + sliceGatewayProvider := workerv1alpha1.WorkerSliceGatewayProvider{ + SliceGatewayType: sliceConfig.Spec.SliceGatewayProvider.SliceGatewayType, + SliceCaType: sliceConfig.Spec.SliceGatewayProvider.SliceCaType, + } + gwSvcTypePresent := false + for _, gwSvcType := range sliceConfig.Spec.SliceGatewayProvider.SliceGatewayServiceType { + if gwSvcType.Cluster == "*" || gwSvcType.Cluster == workerSliceConfig.Labels["worker-cluster"] { + sliceGatewayProvider.SliceGatewayServiceType = gwSvcType.Type + gwSvcTypePresent = true + } + } + if !gwSvcTypePresent { + sliceGatewayProvider.SliceGatewayServiceType = defaultSliceGatewayServiceType + } + // Reconcile the Namespace Isolation Profile controllerIsolationProfile := sliceConfig.Spec.NamespaceIsolationProfile workerIsolationProfile := workerv1alpha1.NamespaceIsolationProfile{