commands/operator-sdk/cmd/up/local.go: set operator name env for ansible and helm
@@ -137,27 +137,21 @@ func upLocal() error {
func upLocalAnsible() error {
logf.SetLogger(logf.ZapLogger(false))
-
- // Set the kubeconfig that the manager will be able to grab
- // only set env var if user explicitly specified a kubeconfig path
- if kubeConfig != "" {
- if err := os.Setenv(k8sutil.KubeConfigEnvVar, kubeConfig); err != nil {
- return fmt.Errorf("failed to set %s environment variable: (%v)", k8sutil.KubeConfigEnvVar, err)
- }
- }
- // Set the namespace that the manager will be able to grab
- if namespace != "" {
- if err := os.Setenv(k8sutil.WatchNamespaceEnvVar, namespace); err != nil {
- return fmt.Errorf("failed to set %s environment variable: (%v)", k8sutil.WatchNamespaceEnvVar, err)
- }
+ if err := setupOperatorEnv(); err != nil {
+ return err
}
-
return ansible.Run(ansibleOperatorFlags)
}
func upLocalHelm() error {
logf.SetLogger(logf.ZapLogger(false))
+ if err := setupOperatorEnv(); err != nil {
+ return err
+ }
+ return helm.Run(helmOperatorFlags)
+}
+func setupOperatorEnv() error {
// Set the kubeconfig that the manager will be able to grab
// only set env var if user explicitly specified a kubeconfig path
if kubeConfig != "" {
@@ -171,8 +165,15 @@ func upLocalHelm() error {
return fmt.Errorf("failed to set %s environment variable: (%v)", k8sutil.WatchNamespaceEnvVar, err)
}
}
-
- return helm.Run(helmOperatorFlags)
+ // Set the operator name, if not already set
+ projutil.MustInProjectRoot()
+ if _, err := k8sutil.GetOperatorName(); err != nil {
+ operatorName := filepath.Base(projutil.MustGetwd())
+ if err := os.Setenv(k8sutil.OperatorNameEnvVar, operatorName); err != nil {
+ return fmt.Errorf("failed to set %s environment variable: (%v)", k8sutil.OperatorNameEnvVar, err)
+ }
+ }
+ return nil
}
func buildLocal(outputBinName string) error {
