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 2 commits
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
10 changes: 10 additions & 0 deletions apis/controller/v1alpha1/sliceconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
// +kubebuilder:validation:Required
//+kubebuilder:validation:Enum:=NodePort;LoadBalancer
Type string `json:"type"`
}

// QOSProfile is the QOS Profile configuration from backend
Expand Down
22 changes: 21 additions & 1 deletion apis/controller/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apis/worker/v1alpha1/workersliceconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions config/crd/bases/controller.kubeslice.io_sliceconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ spec:
sliceCaType:
default: Local
type: string
sliceGatewayServiceType:
items:
properties:
cluster:
type: string
type:
enum:
- NodePort
- LoadBalancer
type: string
required:
- cluster
- type
type: object
type: array
sliceGatewayType:
default: OpenVPN
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ spec:
sliceCaType:
default: Local
type: string
sliceGatewayServiceType:
enum:
- NodePort
- LoadBalancer
type: string
sliceGatewayType:
default: OpenVPN
type: string
Expand Down
7 changes: 4 additions & 3 deletions service/kube_slice_resource_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ var (
)

const (
serverGateway = "Server"
clientGateway = "Client"
workerSliceGatewayType = "OpenVPN"
serverGateway = "Server"
clientGateway = "Client"
workerSliceGatewayType = "OpenVPN"
defaultSliceGatewayServiceType = "NodePort"
)

var (
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
20 changes: 19 additions & 1 deletion service/worker_slice_config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
mridulgain marked this conversation as resolved.
Show resolved Hide resolved
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{
Expand All @@ -237,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