Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@ spec:
description: Spec represents the desired deployment configuration of Klusterlet
agent.
properties:
agentConfiguration:
description: |-
AgentConfiguration contains the configuration of the klusterlet agents,
such as the bind ports of their health probe and metrics endpoints.
properties:
bindConfiguration:
description: BindConfiguration represents the server bind configuration
of the klusterlet agents.
properties:
healthProbePort:
default: 8443
description: |-
HealthProbePort represents the bind port of the agents' health check endpoint. The default value is 8443.
Agents run as non-root, so privileged ports below 1024 are not allowed.
format: int32
maximum: 65535
minimum: 1024
type: integer
hostNetwork:
description: HostNetwork enables running the agent pods in
host networking mode.
type: boolean
metricsPort:
default: 8080
description: |-
MetricsPort represents the bind port of the agents' metrics endpoint. The default value is 8080.
Metrics may be disabled by setting a value less than or equal to 0.
format: int32
maximum: 65535
type: integer
type: object
type: object
clusterName:
description: |-
clusterName is the name of the managed cluster to be created on hub.
Expand Down
34 changes: 34 additions & 0 deletions operator/v1/types_klusterlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,40 @@ type KlusterletSpec struct {
// is not available on the managed cluster.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`

// AgentConfiguration contains the configuration of the klusterlet agents,
// such as the bind ports of their health probe and metrics endpoints.
// +optional
AgentConfiguration *AgentConfiguration `json:"agentConfiguration,omitempty"`
}

// AgentConfiguration represents customization of the klusterlet agents.
type AgentConfiguration struct {
// BindConfiguration represents the server bind configuration of the klusterlet agents.
// +optional
BindConfiguration *AgentBindConfiguration `json:"bindConfiguration,omitempty"`
}

// AgentBindConfiguration represents customization of the server bindings of the klusterlet agents.
type AgentBindConfiguration struct {
// HealthProbePort represents the bind port of the agents' health check endpoint. The default value is 8443.
// Agents run as non-root, so privileged ports below 1024 are not allowed.
// +optional
// +kubebuilder:default=8443
// +kubebuilder:validation:Minimum=1024
// +kubebuilder:validation:Maximum=65535
HealthProbePort int32 `json:"healthProbePort,omitempty"`

// MetricsPort represents the bind port of the agents' metrics endpoint. The default value is 8080.
// Metrics may be disabled by setting a value less than or equal to 0.
// +optional
// +kubebuilder:default=8080
// +kubebuilder:validation:Maximum=65535
MetricsPort int32 `json:"metricsPort"`

// HostNetwork enables running the agent pods in host networking mode.
// +optional
HostNetwork bool `json:"hostNetwork,omitempty"`
}

// ServerURL represents the apiserver url and ca bundle that is accessible externally
Expand Down
42 changes: 42 additions & 0 deletions operator/v1/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions operator/v1/zz_generated.model_name.go

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

51 changes: 51 additions & 0 deletions test/integration/api/klusterlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,57 @@ var _ = Describe("Klusterlet API test with WorkConfiguration", func() {
})
})

var _ = Describe("Klusterlet API test with AgentConfiguration", func() {
var klusterlet *operatorv1.Klusterlet

BeforeEach(func() {
klusterlet = &operatorv1.Klusterlet{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("klusterlet-agentconfig-%s", rand.String(5)),
},
}
})

AfterEach(func() {
err := operatorClient.OperatorV1().Klusterlets().Delete(context.TODO(), klusterlet.Name, metav1.DeleteOptions{})
if !apierrors.IsNotFound(err) {
Expect(err).ToNot(HaveOccurred())
}
})

withBindConfiguration := func(bind *operatorv1.AgentBindConfiguration) {
klusterlet.Spec.AgentConfiguration = &operatorv1.AgentConfiguration{BindConfiguration: bind}
}

It("should default the health probe port and keep a zero metrics port", func() {
withBindConfiguration(&operatorv1.AgentBindConfiguration{})
created, err := operatorClient.OperatorV1().Klusterlets().Create(context.TODO(), klusterlet, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(created.Spec.AgentConfiguration.BindConfiguration.HealthProbePort).Should(Equal(int32(8443)))
Expect(created.Spec.AgentConfiguration.BindConfiguration.MetricsPort).Should(Equal(int32(0)))
Expect(created.Spec.AgentConfiguration.BindConfiguration.HostNetwork).Should(BeFalse())
})

It("should accept custom ports with host network", func() {
withBindConfiguration(&operatorv1.AgentBindConfiguration{
HealthProbePort: 9443,
MetricsPort: 9090,
HostNetwork: true,
})
created, err := operatorClient.OperatorV1().Klusterlets().Create(context.TODO(), klusterlet, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(created.Spec.AgentConfiguration.BindConfiguration.HealthProbePort).Should(Equal(int32(9443)))
Expect(created.Spec.AgentConfiguration.BindConfiguration.MetricsPort).Should(Equal(int32(9090)))
Expect(created.Spec.AgentConfiguration.BindConfiguration.HostNetwork).Should(BeTrue())
})

It("should reject a privileged health probe port", func() {
withBindConfiguration(&operatorv1.AgentBindConfiguration{HealthProbePort: 80})
_, err := operatorClient.OperatorV1().Klusterlets().Create(context.TODO(), klusterlet, metav1.CreateOptions{})
Expect(err).To(HaveOccurred())
})
})

var _ = Describe("Klusterlet v1 Enhanced API test", func() {
var klusterletName string

Expand Down
Loading