-
Notifications
You must be signed in to change notification settings - Fork 30
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
Refactor name setting for complex cases #174
Refactor name setting for complex cases #174
Conversation
policies: | ||
- name: one | ||
manifests: | ||
- path: {{printf "%v/%v" .Dir "configmap.yaml"}} | ||
name: tiger | ||
- path: {{printf "%v/%v" .Dir "configmap.yaml"}} |
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.
Although this manifest path name
has "rabbit", this name is ignored because it is consolidateManifests. The configuration name will be "tiger"
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.
It feels like this test has a lot going on, I couldn't quite follow what it was doing. Can it be split into multiple tests? Or does it need to be all together in one?
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.
I understand I wanted to cover most of the edge cases. because base cases are covered in other unit tests
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.
I can say this is the ULTIMATE test case.
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.
Maybe it is good idea to split Let me think
802d4cc
to
5ad152b
Compare
policies: | ||
- name: one | ||
manifests: | ||
- path: {{printf "%v/%v" .Dir "configmap.yaml"}} | ||
name: tiger | ||
- path: {{printf "%v/%v" .Dir "configmap.yaml"}} |
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.
It feels like this test has a lot going on, I couldn't quite follow what it was doing. Can it be split into multiple tests? Or does it need to be all together in one?
internal/utils.go
Outdated
func getConfigurationPolicyName(policyConf *types.PolicyConfig, manifestGroupIndex int, | ||
usedPolicyNameNum *int, usedManifestNameNum *int, |
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.
Passing these int
s as pointers makes it possible to increment them conditionally, but it seems hard to reason about without looking through this entire function. Maybe it's just too clever for me.
I wonder if returning the updated values would help? Or maybe there needs to be a comment when this function is called.
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.
It is related to previous PR sorry about confusing
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.
Inside the function, we don't know which name is used so
internal/utils.go
Outdated
getConfigurationPolicyName(policyConf, i, | ||
&usedPolicyNameNum, &usedManifestNameNum), |
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.
I wonder if this kind of thing would help me:
getConfigurationPolicyName(policyConf, i, | |
&usedPolicyNameNum, &usedManifestNameNum), | |
usedPolicyNameNum, usedManifestNameNum = getConfigurationPolicyName(policyConf, i, | |
usedPolicyNameNum, usedManifestNameNum), |
But it's kind of long, maybe it's not better 😓
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.
Looks good! The counter is definitely tricky. I've left some comments to consider.
I also keep going back and forth in my mind on whether we should adjust the current numbering system. This is how it should have been implemented originally, but it is a change in behavior and, if we're going to implement this, it shouldn't be backported.
internal/utils.go
Outdated
// For the case where ConsolidateManifests is true and the manifest's name is provided, | ||
if usedManifestNameNum == nil && configName != "" { | ||
return configName | ||
} | ||
|
||
if usedManifestNameNum != nil && configName != "" { | ||
*usedManifestNameNum++ | ||
if *usedManifestNameNum > 1 { | ||
return fmt.Sprintf("%s%d", configName, *usedManifestNameNum) | ||
} | ||
|
||
return configName | ||
} |
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.
This could be combined (also incorporates proposed changes to not use manifests.name
when consolidateManifests: true
)
// For the case where ConsolidateManifests is true and the manifest's name is provided, | |
if usedManifestNameNum == nil && configName != "" { | |
return configName | |
} | |
if usedManifestNameNum != nil && configName != "" { | |
*usedManifestNameNum++ | |
if *usedManifestNameNum > 1 { | |
return fmt.Sprintf("%s%d", configName, *usedManifestNameNum) | |
} | |
return configName | |
} | |
// The manifest name is provided | |
if usedManifestNameNum != nil && configName != "" { | |
*usedManifestNameNum++ | |
if *usedManifestNameNum > 1 { | |
return fmt.Sprintf("%s%d", configName, *usedManifestNameNum) | |
} | |
return configName | |
} |
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.
Should we add error message or warning message for this, otherwise this is really confusing usesr.
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.
Brian commented https://issues.redhat.com/browse/ACM-12563
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.
I don't think it's confusing for the user since the manifests are being combined so it's using the parent configuration, and I think (?) this PR resolves Brian's code bug since the manifest[].name
is handled separately for object-templates-raw
.
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.
Oh, I see. I wasn't thinking about this allowing configuration of the ConfigurationPolicy to have a different name than the Policy. Yes, this makes sense then to just use the first name it finds.
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.
So leave it as t is?
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.
Leave the logic, yes. I still think the conditionals could optionally be combined:
// The manifest name is provided
if configName != "" {
// The manifest name counter is not nil so must be incremented and used if it's greater than one
if usedManifestNameNum != nil {
*usedManifestNameNum++
if *usedManifestNameNum > 1 {
return fmt.Sprintf("%s%d", configName, *usedManifestNameNum)
}
}
// Return the manifest name without a suffix
return configName
}
I might have to think more about whether we should be doing duplicate name validation, but right now I'm thinking that can be chalked up to user error since the framework would complain once it's deployed.
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.
I am not sure this repos has sonarcloud. Sonar doesn't like too many if-if child.
5ad152b
to
a069b6d
Compare
https://issues.redhat.com/browse/ACM-12563 Signed-off-by: yiraeChristineKim <[email protected]>
a069b6d
to
7516117
Compare
/hold for other reviews |
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.
There are some edge cases here where the same name could be specified throughout for policies[].name
and manifests[].name
.
Though for policies[].name
, it was a blocking thing since the object couldn't be deployed at all so it really needed to be an error case. For manifests[].name
, the framework would let the user know that the same name is in use so we could chalk it up to user error and not have it be blocking, which I think I'd be fine with.
I still maintain that the numbering changes should not be backported. If there is a backport, it should only include the portion of this PR dealing with object-templates-raw
.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dhaiducek, mprahl, yiraeChristineKim The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/unhold |
dd1f91f
into
open-cluster-management-io:main
|
This PR supports the more complex cases of setting names. Especially,
consolidateManifests
is true and themanifest-path name
is present.https://issues.redhat.com/browse/ACM-1256