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 @@ -41,10 +41,12 @@ spec:
properties:
agentInstallNamespace:
default: open-cluster-management-agent-addon
description: AgentInstallNamespace is the namespace where the add-on
agent should be installed on the managed cluster.
description: |-
AgentInstallNamespace is the namespace where the add-on agent should be installed on the managed cluster.
For template-type addons: set to empty string "" to use the namespace defined in the addonTemplate.
For non-template addons: defaults to "open-cluster-management-agent-addon" if not specified.
maxLength: 63
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
customizedVariables:
description: |-
Expand Down
4 changes: 3 additions & 1 deletion addon/v1alpha1/types_addondeploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ type AddOnDeploymentConfigSpec struct {
ProxyConfig ProxyConfig `json:"proxyConfig,omitempty"`

// AgentInstallNamespace is the namespace where the add-on agent should be installed on the managed cluster.
// For template-type addons: set to empty string "" to use the namespace defined in the addonTemplate.
// For non-template addons: defaults to "open-cluster-management-agent-addon" if not specified.
// +optional
// +kubebuilder:default=open-cluster-management-agent-addon
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
// +kubebuilder:validation:Pattern=^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
AgentInstallNamespace string `json:"agentInstallNamespace,omitempty"`

// ResourceRequirements specify the resources required by add-on agents.
Expand Down
95 changes: 95 additions & 0 deletions test/integration/api/addondeploymentconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,99 @@ var _ = ginkgo.Describe("AddOnDeploymentConfig API test", func() {
)
gomega.Expect(errors.IsInvalid(err)).To(gomega.BeTrue())
})

ginkgo.It("Should create a AddOnDeploymentConfig with empty agentInstallNamespace", func() {
addOnDeploymentConfig := &addonv1alpha1.AddOnDeploymentConfig{
ObjectMeta: metav1.ObjectMeta{
Name: addOnDeploymentConfigName,
Namespace: testNamespace,
},
Spec: addonv1alpha1.AddOnDeploymentConfigSpec{
AgentInstallNamespace: "",
},
}

_, err := hubAddonClient.AddonV1alpha1().AddOnDeploymentConfigs(testNamespace).Create(
context.TODO(),
addOnDeploymentConfig,
metav1.CreateOptions{},
)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
})

ginkgo.It("Should create a AddOnDeploymentConfig with valid agentInstallNamespace", func() {
addOnDeploymentConfig := &addonv1alpha1.AddOnDeploymentConfig{
ObjectMeta: metav1.ObjectMeta{
Name: addOnDeploymentConfigName,
Namespace: testNamespace,
},
Spec: addonv1alpha1.AddOnDeploymentConfigSpec{
AgentInstallNamespace: "my-custom-namespace",
},
}

_, err := hubAddonClient.AddonV1alpha1().AddOnDeploymentConfigs(testNamespace).Create(
context.TODO(),
addOnDeploymentConfig,
metav1.CreateOptions{},
)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
})

ginkgo.It("Should not create a AddOnDeploymentConfig with invalid agentInstallNamespace (starts with hyphen)", func() {
addOnDeploymentConfig := &addonv1alpha1.AddOnDeploymentConfig{
ObjectMeta: metav1.ObjectMeta{
Name: addOnDeploymentConfigName,
Namespace: testNamespace,
},
Spec: addonv1alpha1.AddOnDeploymentConfigSpec{
AgentInstallNamespace: "-invalid",
},
}

_, err := hubAddonClient.AddonV1alpha1().AddOnDeploymentConfigs(testNamespace).Create(
context.TODO(),
addOnDeploymentConfig,
metav1.CreateOptions{},
)
gomega.Expect(errors.IsInvalid(err)).To(gomega.BeTrue())
})

ginkgo.It("Should not create a AddOnDeploymentConfig with invalid agentInstallNamespace (contains uppercase)", func() {
addOnDeploymentConfig := &addonv1alpha1.AddOnDeploymentConfig{
ObjectMeta: metav1.ObjectMeta{
Name: addOnDeploymentConfigName,
Namespace: testNamespace,
},
Spec: addonv1alpha1.AddOnDeploymentConfigSpec{
AgentInstallNamespace: "Invalid-Namespace",
},
}

_, err := hubAddonClient.AddonV1alpha1().AddOnDeploymentConfigs(testNamespace).Create(
context.TODO(),
addOnDeploymentConfig,
metav1.CreateOptions{},
)
gomega.Expect(errors.IsInvalid(err)).To(gomega.BeTrue())
})

ginkgo.It("Should not create a AddOnDeploymentConfig with agentInstallNamespace exceeding max length", func() {
addOnDeploymentConfig := &addonv1alpha1.AddOnDeploymentConfig{
ObjectMeta: metav1.ObjectMeta{
Name: addOnDeploymentConfigName,
Namespace: testNamespace,
},
Spec: addonv1alpha1.AddOnDeploymentConfigSpec{
AgentInstallNamespace: rand.String(64), // max is 63
},
}

_, err := hubAddonClient.AddonV1alpha1().AddOnDeploymentConfigs(testNamespace).Create(
context.TODO(),
addOnDeploymentConfig,
metav1.CreateOptions{},
)
gomega.Expect(errors.IsInvalid(err)).To(gomega.BeTrue())
})
})