-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OSPRH-11235] Do not fail when clouds CM exists #240
Merged
openshift-merge-bot
merged 1 commit into
openstack-k8s-operators:main
from
lpiwowar:fix/clouds-cm-creation
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |
"github.com/openstack-k8s-operators/lib-common/modules/common/pvc" | ||
"github.com/openstack-k8s-operators/lib-common/modules/common/util" | ||
v1beta1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1" | ||
"gopkg.in/yaml.v3" | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
|
@@ -550,3 +551,72 @@ func GetCommonRbacRules(privileged bool) []rbacv1.PolicyRule { | |
|
||
return []rbacv1.PolicyRule{rbacPolicyRule} | ||
} | ||
|
||
// Some frameworks like (e.g., Tobiko and Horizon) require password value to be | ||
// present in clouds.yaml. This code ensures that we set a default value of | ||
// 12345678 when password value is missing in the clouds.yaml | ||
func EnsureCloudsConfigMapExists( | ||
ctx context.Context, | ||
instance client.Object, | ||
helper *helper.Helper, | ||
labels map[string]string, | ||
) (ctrl.Result, error) { | ||
const openstackConfigMapName = "openstack-config" | ||
const testOperatorCloudsConfigMapName = "test-operator-clouds-config" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (non-blocking) question: would take the name from pkg.util.common.go ? So we don't need to maintain same const in two different places. |
||
|
||
cm, _, _ := configmap.GetConfigMap( | ||
ctx, | ||
helper, | ||
instance, | ||
testOperatorCloudsConfigMapName, | ||
time.Second*10, | ||
) | ||
if cm.Name == testOperatorCloudsConfigMapName { | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
cm, _, _ = configmap.GetConfigMap( | ||
lpiwowar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx, | ||
helper, | ||
instance, | ||
openstackConfigMapName, | ||
time.Second*10, | ||
) | ||
|
||
result := make(map[string]interface{}) | ||
|
||
err := yaml.Unmarshal([]byte(cm.Data["clouds.yaml"]), &result) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
clouds := result["clouds"].(map[string]interface{}) | ||
defaultValue := clouds["default"].(map[string]interface{}) | ||
auth := defaultValue["auth"].(map[string]interface{}) | ||
|
||
if _, ok := auth["password"].(string); !ok { | ||
auth["password"] = "12345678" | ||
} | ||
|
||
yamlString, err := yaml.Marshal(result) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
cms := []util.Template{ | ||
{ | ||
Name: testOperatorCloudsConfigMapName, | ||
Namespace: instance.GetNamespace(), | ||
Labels: labels, | ||
CustomData: map[string]string{ | ||
"clouds.yaml": string(yamlString), | ||
}, | ||
}, | ||
} | ||
err = configmap.EnsureConfigMaps(ctx, helper, instance, cms, nil) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
} |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(blocking) question: I guess this one is not required right? Related as well with @kstrenkova
comment.
Found TestOperatorCloudsConfigMapName in the volumes.go files.