Skip to content

Commit

Permalink
✨ add work driver config to cluster manager. (#323)
Browse files Browse the repository at this point in the history
* add work driver to cluster manager.

Signed-off-by: morvencao <[email protected]>

* add testing.

Signed-off-by: morvencao <[email protected]>

* define work driver type.

Signed-off-by: morvencao <[email protected]>

---------

Signed-off-by: morvencao <[email protected]>
  • Loading branch information
morvencao authored Mar 20, 2024
1 parent 29e1b1d commit 19eb7b5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ spec:
type: string
type: object
workConfiguration:
default:
workDriver: kube
description: WorkConfiguration contains the configuration of work
properties:
featureGates:
Expand Down Expand Up @@ -356,6 +358,22 @@ spec:
- feature
type: object
type: array
workDriver:
default: kube
description: "WorkDriver represents the type of work driver. Possible
values are \"kube\", \"mqtt\", or \"grpc\". If not provided,
the default value is \"kube\". If set to non-\"kube\" drivers,
the klusterlet need to use the same driver. and the driver configuration
must be provided in a secret named \"work-driver-config\" in
the namespace where the cluster manager is running, adhering
to the following structure: config.yaml: | <driver-config-in-yaml>
\n For detailed driver configuration, please refer to the sdk-go
documentation: https://github.com/open-cluster-management-io/sdk-go/blob/main/pkg/cloudevents/README.md#supported-protocols-and-drivers"
enum:
- kube
- mqtt
- grpc
type: string
type: object
workImagePullSpec:
default: quay.io/open-cluster-management/work
Expand Down
28 changes: 28 additions & 0 deletions operator/v1/types_clustermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type ClusterManagerSpec struct {

// WorkConfiguration contains the configuration of work
// +optional
// +kubebuilder:default={workDriver: kube}
WorkConfiguration *WorkConfiguration `json:"workConfiguration,omitempty"`

// AddOnManagerConfiguration contains the configuration of addon manager
Expand Down Expand Up @@ -119,8 +120,35 @@ type WorkConfiguration struct {
// he can set featuregate/Foo=false before upgrading. Let's say the cluster-admin wants featuregate/Foo=false.
// +optional
FeatureGates []FeatureGate `json:"featureGates,omitempty"`

// WorkDriver represents the type of work driver. Possible values are "kube", "mqtt", or "grpc".
// If not provided, the default value is "kube".
// If set to non-"kube" drivers, the klusterlet need to use the same driver.
// and the driver configuration must be provided in a secret named "work-driver-config"
// in the namespace where the cluster manager is running, adhering to the following structure:
// config.yaml: |
// <driver-config-in-yaml>
//
// For detailed driver configuration, please refer to the sdk-go documentation: https://github.com/open-cluster-management-io/sdk-go/blob/main/pkg/cloudevents/README.md#supported-protocols-and-drivers
//
// +optional
// +kubebuilder:default:=kube
// +kubebuilder:validation:Enum=kube;mqtt;grpc
WorkDriver WorkDriverType `json:"workDriver,omitempty"`
}

// WorkDriverType represents the type of work driver.
type WorkDriverType string

const (
// WorkDriverTypeKube is the work driver type for kube.
WorkDriverTypeKube WorkDriverType = "kube"
// WorkDriverTypeMqtt is the work driver type for mqtt.
WorkDriverTypeMqtt WorkDriverType = "mqtt"
// WorkDriverTypeGrpc is the work driver type for grpc.
WorkDriverTypeGrpc WorkDriverType = "grpc"
)

type AddOnManagerConfiguration struct {
// FeatureGates represents the list of feature gates for addon manager
// If it is set empty, default feature gates will be used.
Expand Down
1 change: 1 addition & 0 deletions operator/v1/zz_generated.swagger_doc_generated.go

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

17 changes: 16 additions & 1 deletion test/integration/api/clustermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,22 @@ var _ = Describe("ClusterManager API test with WorkConfiguration", func() {
clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Create(context.TODO(), clusterManager, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

Expect(clusterManager.Spec.WorkConfiguration).To(BeNil())
Expect(clusterManager.Spec.WorkConfiguration.WorkDriver).Should(Equal(operatorv1.WorkDriverTypeKube))
})

It("Create a cluster manager with wrong driver type", func() {
clusterManager := &operatorv1.ClusterManager{
ObjectMeta: metav1.ObjectMeta{
Name: clusterManagerName,
},
Spec: operatorv1.ClusterManagerSpec{
WorkConfiguration: &operatorv1.WorkConfiguration{
WorkDriver: "WrongDriver",
},
},
}
_, err := operatorClient.OperatorV1().ClusterManagers().Create(context.TODO(), clusterManager, metav1.CreateOptions{})
Expect(err).To(HaveOccurred())
})

It("Create a cluster manager with empty work feature gate mode", func() {
Expand Down

0 comments on commit 19eb7b5

Please sign in to comment.