Skip to content
Draft
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
33 changes: 32 additions & 1 deletion controllers/addoncontroller.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package controllers

import (
"context"
"embed"
"strings"

operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
Expand All @@ -18,6 +20,7 @@ import (
addonframeworkutils "open-cluster-management.io/addon-framework/pkg/utils"
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
clusterv1client "open-cluster-management.io/api/client/cluster/clientset/versioned"
clusterv1 "open-cluster-management.io/api/cluster/v1"
workapiv1 "open-cluster-management.io/api/work/v1"

Expand Down Expand Up @@ -124,7 +127,8 @@ var manifestFilesHelmDeployOpenShift = []string{

// Another agent with registration enabled.
type volsyncAgent struct {
addonClient addonv1alpha1client.Interface
addonClient addonv1alpha1client.Interface
clusterClient clusterv1client.Interface
}

var _ agent.AgentAddon = &volsyncAgent{}
Expand Down Expand Up @@ -182,6 +186,33 @@ func (h *volsyncAgent) GetAgentAddonOptions() agent.AgentAddonOptions {
SupportedConfigGVRs: []schema.GroupVersionResource{
addonframeworkutils.AddOnDeploymentConfigGVR,
},
Registration: &agent.RegistrationOption{
CSRConfigurations: func(cluster *clusterv1.ManagedCluster,
addon *addonapiv1alpha1.ManagedClusterAddOn) ([]addonapiv1alpha1.RegistrationConfig, error) {
// no-op func, we don't need any CSR configurations
return nil, nil
},
// Set agent install namespace from addon deployment config if it exists or our our default
AgentInstallNamespace: getVolsyncInstallNamespaceFunc(h.addonClient, h.clusterClient),
},
}
}

func getVolsyncInstallNamespaceFunc(
addonClient addonv1alpha1client.Interface,
clusterClient clusterv1client.Interface,
) func(addon *addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
return func(addon *addonapiv1alpha1.ManagedClusterAddOn) (string, error) {
// Lookup cluster
managedCluster, err := clusterClient.ClusterV1().ManagedClusters().
Get(context.TODO(), addon.Namespace /* this is the mgd cluster name */, metav1.GetOptions{})
if err != nil {
return "", err
}

// ManifestHelper will get the install namespace (will be different for helm and operator deployments)
mh := getManifestHelper(embedFS, addonClient, managedCluster, addon)
return mh.getInstallNamespace()
}
}

Expand Down
28 changes: 22 additions & 6 deletions controllers/addoncontroller_legacyolm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ var _ = Describe("Addoncontroller - legacy OLM deployment tests", func() {
}

BeforeEach(func() {
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", nil, nil)
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", "", nil, nil)
})
AfterEach(func() {
cleanupAddonDeploymentConfig(addonDeploymentConfig, true)
Expand Down Expand Up @@ -611,7 +611,7 @@ var _ = Describe("Addoncontroller - legacy OLM deployment tests", func() {
},
}
BeforeEach(func() {
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", nil, nil)
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", "", nil, nil)

// Update the managedclusteraddon before we create it to add the addondeploymentconfig
mcAddon.Spec.Configs = []addonv1alpha1.AddOnConfig{
Expand Down Expand Up @@ -687,7 +687,7 @@ var _ = Describe("Addoncontroller - legacy OLM deployment tests", func() {
},
}
BeforeEach(func() {
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", nil, nil)
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", "", nil, nil)

// Update the managedclusteraddon before we create it to add the addondeploymentconfig
mcAddon.Spec.Configs = []addonv1alpha1.AddOnConfig{
Expand Down Expand Up @@ -772,7 +772,7 @@ var _ = Describe("Addoncontroller - legacy OLM deployment tests", func() {
},
}
BeforeEach(func() {
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", nil, nil)
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", "", nil, nil)

// Update the managedclusteraddon before we create it to add the addondeploymentconfig
mcAddon.Spec.Configs = []addonv1alpha1.AddOnConfig{
Expand Down Expand Up @@ -869,7 +869,7 @@ var _ = Describe("Addoncontroller - legacy OLM deployment tests", func() {
},
}

defaultAddonDeploymentConfig = createAddonDeploymentConfig(defaultNodePlacement, "", "", nil, nil)
defaultAddonDeploymentConfig = createAddonDeploymentConfig(defaultNodePlacement, "", "", "", nil, nil)

// Update the ClusterManagementAddOn before we create it to set a default deployment config
clusterManagementAddon.Spec.SupportedConfigs[0].DefaultConfig = &addonv1alpha1.ConfigReferent{
Expand Down Expand Up @@ -1080,7 +1080,7 @@ var _ = Describe("Addoncontroller - legacy OLM deployment tests", func() {
},
}
BeforeEach(func() {
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", nil, nil)
addonDeploymentConfig = createAddonDeploymentConfig(nodePlacement, "", "", "", nil, nil)

// Update the managedclusteraddon before we create it to add the addondeploymentconfig
mcAddon.Spec.Configs = []addonv1alpha1.AddOnConfig{
Expand Down Expand Up @@ -1539,6 +1539,22 @@ var _ = Describe("Addon Status Update Tests", func() {
Expect(statusCondition.Status).To(Equal(metav1.ConditionTrue))
Expect(statusCondition.Message).To(ContainSubstring("volsync add-on is available"))
})

It("Should update the status with the install namespace", func() {
Eventually(func() bool {
err := testK8sClient.Get(testCtx, types.NamespacedName{
Name: "volsync",
Namespace: testManagedClusterNamespace.GetName(),
}, mcAddon)
if err != nil {
return false
}

return mcAddon.Status.Namespace != ""
}, timeout, interval).Should(BeTrue())

Expect(mcAddon.Status.Namespace).To(Equal("openshift-operators")) // hardcoded for olm deploy
})
})
})
})
Expand Down
Loading