Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AM-11526,AM-11741): Slice Gateway External LoadBalancer #180

Merged
merged 13 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apis/controller/v1alpha1/sliceconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ type WorkerSliceGatewayProvider struct {

type SliceGatewayServiceType struct {
// +kubebuilder:validation:Required
Cluster string `json:"cluster,omitempty"`
mridulgain marked this conversation as resolved.
Show resolved Hide resolved
Cluster string `json:"cluster"`
// +kubebuilder:validation:Required
//+kubebuilder:validation:Enum:=NodePort;LoadBalancer
Type string `json:"type,omitempty"`
Type string `json:"type"`
}

// QOSProfile is the QOS Profile configuration from backend
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/controller.kubeslice.io_sliceconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ spec:
- NodePort
- LoadBalancer
type: string
required:
- cluster
- type
type: object
type: array
sliceGatewayType:
Expand Down
28 changes: 28 additions & 0 deletions service/slice_config_webhook_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func ValidateSliceConfigCreate(ctx context.Context, sliceConfig *controllerv1alp
if err := validateClustersOnCreate(ctx, sliceConfig); err != nil {
return apierrors.NewInvalid(schema.GroupKind{Group: apiGroupKubeSliceControllers, Kind: "SliceConfig"}, sliceConfig.Name, field.ErrorList{err})
}
if err := validateSlicegatewayServiceType(ctx, sliceConfig); err != nil {
return apierrors.NewInvalid(schema.GroupKind{Group: apiGroupKubeSliceControllers, Kind: "SliceConfig"}, sliceConfig.Name, field.ErrorList{err})
}
if err := validateQosProfile(ctx, sliceConfig); err != nil {
return apierrors.NewInvalid(schema.GroupKind{Group: apiGroupKubeSliceControllers, Kind: "SliceConfig"}, sliceConfig.Name, field.ErrorList{err})
}
Expand Down Expand Up @@ -78,6 +81,9 @@ func ValidateSliceConfigUpdate(ctx context.Context, sliceConfig *controllerv1alp
if err := validateClustersOnUpdate(ctx, sliceConfig, old); err != nil {
return apierrors.NewInvalid(schema.GroupKind{Group: apiGroupKubeSliceControllers, Kind: "SliceConfig"}, sliceConfig.Name, field.ErrorList{err})
}
if err := validateSlicegatewayServiceType(ctx, sliceConfig); err != nil {
return apierrors.NewInvalid(schema.GroupKind{Group: apiGroupKubeSliceControllers, Kind: "SliceConfig"}, sliceConfig.Name, field.ErrorList{err})
}
if err := validateQosProfile(ctx, sliceConfig); err != nil {
return apierrors.NewInvalid(schema.GroupKind{Group: apiGroupKubeSliceControllers, Kind: "SliceConfig"}, sliceConfig.Name, field.ErrorList{err})
}
Expand Down Expand Up @@ -330,6 +336,28 @@ func validateClustersOnUpdate(ctx context.Context, sliceConfig *controllerv1alph
return nil
}

// to validate the SlicegatewayServiceType array
func validateSlicegatewayServiceType(ctx context.Context, sliceConfig *controllerv1alpha1.SliceConfig) *field.Error {
freq := make(map[string]int)
for _, sliceGwSvcType := range sliceConfig.Spec.SliceGatewayProvider.SliceGatewayServiceType {
cluster := sliceGwSvcType.Cluster
freq[cluster] += 1
// cluster name can't be empty
if cluster == "" {
return field.Invalid(field.NewPath("Spec").Child("SliceGatewayProvider").Child("SliceGatewayServiceType").Child("Cluster"), cluster, "Cluster name can't be empty")
}
// cluster should participate in slice
if cluster != "*" && !util.ContainsString(sliceConfig.Spec.Clusters, cluster) {
return field.Invalid(field.NewPath("Spec").Child("SliceGatewayProvider").Child("SliceGatewayServiceType").Child("Cluster"), cluster, "Cluster is not participating in slice config")
}
// don't allow duplicate cluster values
if freq[cluster] > 1 {
return field.Invalid(field.NewPath("Spec").Child("SliceGatewayProvider").Child("SliceGatewayServiceType").Child("Cluster"), cluster, "Duplicate entries are not allowed")
}
}
return nil
}

// preventUpdate is a function to stop/avoid the update of config of slice
func preventUpdate(ctx context.Context, sc *controllerv1alpha1.SliceConfig, old runtime.Object) *field.Error {
sliceConfig := old.(*controllerv1alpha1.SliceConfig)
Expand Down
1 change: 1 addition & 0 deletions service/worker_slice_config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ outer:
}

workerSliceConfig.Spec.ExternalGatewayConfig = externalGatewayConfig
workerSliceConfig.Spec.SliceGatewayProvider = sliceGatewayProvider
workerSliceConfig.Spec.NamespaceIsolationProfile = workerIsolationProfile
workerSliceConfig.Spec.SliceName = sliceConfig.Name
workerSliceConfig.Spec.Octet = octet
Expand Down
Loading