diff --git a/pkg/operator/controllers/muo/deploy_test.go b/pkg/operator/controllers/muo/deploy_test.go index 966a0dc9348..a1fa47f566d 100644 --- a/pkg/operator/controllers/muo/deploy_test.go +++ b/pkg/operator/controllers/muo/deploy_test.go @@ -65,7 +65,7 @@ func TestDeployCreateOrUpdateCorrectKinds(t *testing.T) { } dh.EXPECT().Ensure(gomock.Any(), gomock.Any()).Do(check).Return(nil) - deployer := deployer.NewDeployer(k8scli, dh, staticFiles) + deployer := deployer.NewDeployer(k8scli, dh, staticFiles, "staticresources") err := deployer.CreateOrUpdate(context.Background(), cluster, &config.MUODeploymentConfig{Pullspec: setPullSpec}) if err != nil { t.Error(err) @@ -137,7 +137,7 @@ func TestDeployCreateOrUpdateSetsOwnerReferences(t *testing.T) { } dh.EXPECT().Ensure(gomock.Any(), gomock.Any()).Do(check).Return(nil) - deployer := deployer.NewDeployer(k8scli, dh, staticFiles) + deployer := deployer.NewDeployer(k8scli, dh, staticFiles, "staticresources") err := deployer.CreateOrUpdate(context.Background(), cluster, &config.MUODeploymentConfig{Pullspec: setPullSpec}) if err != nil { t.Error(err) @@ -160,7 +160,7 @@ func TestDeployDelete(t *testing.T) { dh := mock_dynamichelper.NewMockInterface(controller) dh.EXPECT().EnsureDeleted(gomock.Any(), "Deployment", "openshift-managed-upgrade-operator", "managed-upgrade-operator").Return(nil) - deployer := deployer.NewDeployer(k8scli, dh, staticFiles) + deployer := deployer.NewDeployer(k8scli, dh, staticFiles, "staticresources") err := deployer.Remove(context.Background(), config.MUODeploymentConfig{}) if err != nil { t.Error(err) @@ -175,7 +175,7 @@ func TestDeployDeleteFailure(t *testing.T) { dh := mock_dynamichelper.NewMockInterface(controller) dh.EXPECT().EnsureDeleted(gomock.Any(), "Deployment", "openshift-managed-upgrade-operator", "managed-upgrade-operator").Return(errors.New("fail")) - deployer := deployer.NewDeployer(k8scli, dh, staticFiles) + deployer := deployer.NewDeployer(k8scli, dh, staticFiles, "staticresources") err := deployer.Remove(context.Background(), config.MUODeploymentConfig{}) if err == nil { t.Error(err) @@ -206,7 +206,7 @@ func TestDeployIsReady(t *testing.T) { }, }) - deployer := deployer.NewDeployer(k8scli, nil, staticFiles) + deployer := deployer.NewDeployer(k8scli, nil, staticFiles, "staticresources") ready, err := deployer.IsReady(context.Background(), "openshift-managed-upgrade-operator", "managed-upgrade-operator") if err != nil { t.Error(err) @@ -218,7 +218,7 @@ func TestDeployIsReady(t *testing.T) { func TestDeployIsReadyMissing(t *testing.T) { k8scli := fake.NewSimpleClientset() - deployer := deployer.NewDeployer(k8scli, nil, staticFiles) + deployer := deployer.NewDeployer(k8scli, nil, staticFiles, "staticresources") ready, err := deployer.IsReady(context.Background(), "openshift-managed-upgrade-operator", "managed-upgrade-operator") if err != nil { t.Error(err) @@ -270,7 +270,7 @@ func TestDeployConfig(t *testing.T) { } dh.EXPECT().Ensure(gomock.Any(), gomock.Any()).Do(check).Return(nil) - deployer := deployer.NewDeployer(k8scli, dh, staticFiles) + deployer := deployer.NewDeployer(k8scli, dh, staticFiles, "staticresources") err := deployer.CreateOrUpdate(context.Background(), cluster, tt.deploymentConfig) if err != nil { t.Error(err) diff --git a/pkg/operator/controllers/muo/muo_controller.go b/pkg/operator/controllers/muo/muo_controller.go index b0950514a04..21771ab1fea 100644 --- a/pkg/operator/controllers/muo/muo_controller.go +++ b/pkg/operator/controllers/muo/muo_controller.go @@ -67,7 +67,7 @@ func NewReconciler(arocli aroclient.Interface, kubernetescli kubernetes.Interfac return &Reconciler{ arocli: arocli, kubernetescli: kubernetescli, - deployer: deployer.NewDeployer(kubernetescli, dh, staticFiles), + deployer: deployer.NewDeployer(kubernetescli, dh, staticFiles, "staticresources"), readinessPollTime: 10 * time.Second, readinessTimeout: 5 * time.Minute, diff --git a/pkg/util/deployer/deployer.go b/pkg/util/deployer/deployer.go index 97a6a634092..a0228ac3944 100644 --- a/pkg/util/deployer/deployer.go +++ b/pkg/util/deployer/deployer.go @@ -1,3 +1,5 @@ +// deployer is used to template and deploy services in an ARO cluster. +// Some example usage can be found in the muo package. package deployer // Copyright (c) Microsoft Corporation. @@ -9,6 +11,7 @@ import ( "errors" "io" "io/fs" + "path/filepath" "strings" "text/template" @@ -33,19 +36,21 @@ type deployer struct { kubernetescli kubernetes.Interface dh dynamichelper.Interface fs fs.FS + directory string } -func NewDeployer(kubernetescli kubernetes.Interface, dh dynamichelper.Interface, fs fs.FS) Deployer { +func NewDeployer(kubernetescli kubernetes.Interface, dh dynamichelper.Interface, fs fs.FS, directory string) Deployer { return &deployer{ kubernetescli: kubernetescli, dh: dh, fs: fs, + directory: directory, } } func (depl *deployer) Template(data interface{}, fsys fs.FS) ([]kruntime.Object, error) { results := make([]kruntime.Object, 0) - template, err := template.ParseFS(fsys, "staticresources/*") + template, err := template.ParseFS(fsys, filepath.Join(depl.directory, "*")) if err != nil { return nil, err }