-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(install, crd): add env to enable/disable CRD installation
add OPENEBS_IO_CRD_INSTALL environment variable to enable / disable installation of BlockDevice and BlockDeviceClaim CRDs Signed-off-by: Akhil Mohan <[email protected]>
- Loading branch information
Showing
4 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add env to enable / disable CRD installation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2020 The OpenEBS Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package env | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/openebs/node-disk-manager/pkg/util" | ||
) | ||
|
||
const ( | ||
// INSTALL_CRD_ENV is the environment variable used to check if | ||
// CRDs need to be installed by NDM or not. | ||
INSTALL_CRD_ENV = "OPENEBS_IO_INSTALL_CRD" | ||
|
||
// installCRDEnvDefaultValue is the default value for the INSTALL_CRD_ENV | ||
installCRDEnvDefaultValue = true | ||
) | ||
|
||
// IsInstallCRDEnabled is used to check whether the CRDs need to be installed | ||
func IsInstallCRDEnabled() bool { | ||
val := os.Getenv(INSTALL_CRD_ENV) | ||
|
||
// if empty return the default value | ||
if len(val) == 0 { | ||
return installCRDEnvDefaultValue | ||
} | ||
|
||
return util.CheckTruthy(val) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2020 The OpenEBS Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package env | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsInstallCRDEnabled(t *testing.T) { | ||
tests := map[string]struct { | ||
setEnv bool | ||
envValue string | ||
want bool | ||
}{ | ||
"when INSTALL_CRD_ENV is set to true": { | ||
setEnv: true, | ||
envValue: "true", | ||
want: true, | ||
}, | ||
"when INSTALL_CRD_ENV is set to false": { | ||
setEnv: true, | ||
envValue: "false", | ||
}, | ||
"when INSTALL_CRD_ENV is not set": { | ||
setEnv: false, | ||
want: true, | ||
}, | ||
"when INSTALL_CRD is set to empty": { | ||
setEnv: true, | ||
envValue: "", | ||
want: true, | ||
}, | ||
} | ||
for name, tt := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
if tt.setEnv { | ||
os.Setenv(INSTALL_CRD_ENV, tt.envValue) | ||
} | ||
assert.Equal(t, tt.want, IsInstallCRDEnabled()) | ||
_ = os.Unsetenv(INSTALL_CRD_ENV) | ||
}) | ||
} | ||
} |