Skip to content

Commit 19eb7b5

Browse files
authored
✨ add work driver config to cluster manager. (#323)
* 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]>
1 parent 29e1b1d commit 19eb7b5

4 files changed

+63
-1
lines changed

operator/v1/0000_01_operator.open-cluster-management.io_clustermanagers.crd.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ spec:
323323
type: string
324324
type: object
325325
workConfiguration:
326+
default:
327+
workDriver: kube
326328
description: WorkConfiguration contains the configuration of work
327329
properties:
328330
featureGates:
@@ -356,6 +358,22 @@ spec:
356358
- feature
357359
type: object
358360
type: array
361+
workDriver:
362+
default: kube
363+
description: "WorkDriver represents the type of work driver. Possible
364+
values are \"kube\", \"mqtt\", or \"grpc\". If not provided,
365+
the default value is \"kube\". If set to non-\"kube\" drivers,
366+
the klusterlet need to use the same driver. and the driver configuration
367+
must be provided in a secret named \"work-driver-config\" in
368+
the namespace where the cluster manager is running, adhering
369+
to the following structure: config.yaml: | <driver-config-in-yaml>
370+
\n For detailed driver configuration, please refer to the sdk-go
371+
documentation: https://github.com/open-cluster-management-io/sdk-go/blob/main/pkg/cloudevents/README.md#supported-protocols-and-drivers"
372+
enum:
373+
- kube
374+
- mqtt
375+
- grpc
376+
type: string
359377
type: object
360378
workImagePullSpec:
361379
default: quay.io/open-cluster-management/work

operator/v1/types_clustermanager.go

+28
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type ClusterManagerSpec struct {
6565

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

7071
// AddOnManagerConfiguration contains the configuration of addon manager
@@ -119,8 +120,35 @@ type WorkConfiguration struct {
119120
// he can set featuregate/Foo=false before upgrading. Let's say the cluster-admin wants featuregate/Foo=false.
120121
// +optional
121122
FeatureGates []FeatureGate `json:"featureGates,omitempty"`
123+
124+
// WorkDriver represents the type of work driver. Possible values are "kube", "mqtt", or "grpc".
125+
// If not provided, the default value is "kube".
126+
// If set to non-"kube" drivers, the klusterlet need to use the same driver.
127+
// and the driver configuration must be provided in a secret named "work-driver-config"
128+
// in the namespace where the cluster manager is running, adhering to the following structure:
129+
// config.yaml: |
130+
// <driver-config-in-yaml>
131+
//
132+
// 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
133+
//
134+
// +optional
135+
// +kubebuilder:default:=kube
136+
// +kubebuilder:validation:Enum=kube;mqtt;grpc
137+
WorkDriver WorkDriverType `json:"workDriver,omitempty"`
122138
}
123139

140+
// WorkDriverType represents the type of work driver.
141+
type WorkDriverType string
142+
143+
const (
144+
// WorkDriverTypeKube is the work driver type for kube.
145+
WorkDriverTypeKube WorkDriverType = "kube"
146+
// WorkDriverTypeMqtt is the work driver type for mqtt.
147+
WorkDriverTypeMqtt WorkDriverType = "mqtt"
148+
// WorkDriverTypeGrpc is the work driver type for grpc.
149+
WorkDriverTypeGrpc WorkDriverType = "grpc"
150+
)
151+
124152
type AddOnManagerConfiguration struct {
125153
// FeatureGates represents the list of feature gates for addon manager
126154
// If it is set empty, default feature gates will be used.

operator/v1/zz_generated.swagger_doc_generated.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/api/clustermanager_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,22 @@ var _ = Describe("ClusterManager API test with WorkConfiguration", func() {
281281
clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Create(context.TODO(), clusterManager, metav1.CreateOptions{})
282282
Expect(err).ToNot(HaveOccurred())
283283

284-
Expect(clusterManager.Spec.WorkConfiguration).To(BeNil())
284+
Expect(clusterManager.Spec.WorkConfiguration.WorkDriver).Should(Equal(operatorv1.WorkDriverTypeKube))
285+
})
286+
287+
It("Create a cluster manager with wrong driver type", func() {
288+
clusterManager := &operatorv1.ClusterManager{
289+
ObjectMeta: metav1.ObjectMeta{
290+
Name: clusterManagerName,
291+
},
292+
Spec: operatorv1.ClusterManagerSpec{
293+
WorkConfiguration: &operatorv1.WorkConfiguration{
294+
WorkDriver: "WrongDriver",
295+
},
296+
},
297+
}
298+
_, err := operatorClient.OperatorV1().ClusterManagers().Create(context.TODO(), clusterManager, metav1.CreateOptions{})
299+
Expect(err).To(HaveOccurred())
285300
})
286301

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

0 commit comments

Comments
 (0)