From f9eef6d6743971623a0b85df9dd4a412f939ad04 Mon Sep 17 00:00:00 2001 From: kmova Date: Tue, 12 May 2020 05:08:00 +0000 Subject: [PATCH] feat(install): enable/disable crd installation When helm install for openebs was introduced, there was no way for helm to install CRDs. So api-server included the code to install the CRDs as part of initialization. With Helm 3, the CRDs can be installed via helm. There have been some requests for moving the CRD installations outside of the code for cases where Kubernetes installers like Lokomotive and others, would like granular control on how the required objects are installed. This commit adds an ENV variable that allows users to enable/disable the CRD install code. Signed-off-by: kmova --- pkg/install/v1alpha1/env.go | 8 ++++++++ pkg/install/v1alpha1/env_setter.go | 4 ++++ pkg/install/v1alpha1/env_setter_test.go | 2 +- pkg/install/v1alpha1/flags.go | 7 +++++++ pkg/install/v1alpha1/openebs_crds.go | 2 +- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/install/v1alpha1/env.go b/pkg/install/v1alpha1/env.go index 39d59b2862..8b232c6893 100644 --- a/pkg/install/v1alpha1/env.go +++ b/pkg/install/v1alpha1/env.go @@ -35,4 +35,12 @@ const ( // // Default is "true" CreateDefaultStorageConfig menv.ENVKey = "OPENEBS_IO_CREATE_DEFAULT_STORAGE_CONFIG" + + // InstallCRD is the environment + // variable that flags if maya apiserver should install the CRDs + // As the installation moves towards helm 3, the responsibility of installing + // CRDs can be pushed to helm. + // + // Default is "true" + InstallCRD menv.ENVKey = "OPENEBS_IO_INSTALL_CRD" ) diff --git a/pkg/install/v1alpha1/env_setter.go b/pkg/install/v1alpha1/env_setter.go index 62b0212688..967f40110d 100644 --- a/pkg/install/v1alpha1/env_setter.go +++ b/pkg/install/v1alpha1/env_setter.go @@ -211,6 +211,10 @@ func (e *envInstall) List() (l *envList, err error) { Key: DefaultCstorSparsePool, Value: "false", }) + l.Items = append(l.Items, &env{ + Key: InstallCRD, + Value: "true", + }) l.Items = append(l.Items, &env{ Key: menv.CASTemplateFeatureGateENVK, Value: "true", diff --git a/pkg/install/v1alpha1/env_setter_test.go b/pkg/install/v1alpha1/env_setter_test.go index 534a3b19a8..0ffd0fa302 100644 --- a/pkg/install/v1alpha1/env_setter_test.go +++ b/pkg/install/v1alpha1/env_setter_test.go @@ -26,7 +26,7 @@ func TestEnvInstallCount(t *testing.T) { tests := map[string]struct { expectedCount int }{ - "101": {20}, + "101": {21}, } for name, mock := range tests { diff --git a/pkg/install/v1alpha1/flags.go b/pkg/install/v1alpha1/flags.go index cc59849d52..c421f2d13e 100644 --- a/pkg/install/v1alpha1/flags.go +++ b/pkg/install/v1alpha1/flags.go @@ -37,3 +37,10 @@ func IsCstorSparsePoolEnabled() bool { enabled, _ := strconv.ParseBool(menv.Get(DefaultCstorSparsePool)) return IsDefaultStorageConfigEnabled() && enabled } + +// IsInstallCRDEnabled reads from env variable to check +// whether CRDs should be created by default or not. +func IsInstallCRDEnabled() (enabled bool) { + enabled, _ = strconv.ParseBool(menv.Get(InstallCRD)) + return +} diff --git a/pkg/install/v1alpha1/openebs_crds.go b/pkg/install/v1alpha1/openebs_crds.go index 120e53835b..24eaf94520 100644 --- a/pkg/install/v1alpha1/openebs_crds.go +++ b/pkg/install/v1alpha1/openebs_crds.go @@ -469,7 +469,7 @@ spec: // OpenEBSCRDArtifacts returns the CRDs required for latest version func OpenEBSCRDArtifacts() (list artifactList) { - list.Items = append(list.Items, ParseArtifactListFromMultipleYamls(openEBSCRDs{})...) + list.Items = append(list.Items, ParseArtifactListFromMultipleYamlsIf(openEBSCRDs{}, IsInstallCRDEnabled)...) return }