Skip to content
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

Conversation

yiraeChristineKim
Copy link
Contributor

This PR supports the more complex cases of setting names. Especially, consolidateManifests is true and the manifest-path name is present.
https://issues.redhat.com/browse/ACM-1256

policies:
- name: one
manifests:
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
name: tiger
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
Copy link
Contributor Author

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"

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@yiraeChristineKim yiraeChristineKim Aug 1, 2024

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

policies:
- name: one
manifests:
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
name: tiger
- path: {{printf "%v/%v" .Dir "configmap.yaml"}}
Copy link
Member

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?

Comment on lines 332 to 333
func getConfigurationPolicyName(policyConf *types.PolicyConfig, manifestGroupIndex int,
usedPolicyNameNum *int, usedManifestNameNum *int,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing these ints 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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Comment on lines 268 to 269
getConfigurationPolicyName(policyConf, i,
&usedPolicyNameNum, &usedManifestNameNum),
Copy link
Member

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:

Suggested change
getConfigurationPolicyName(policyConf, i,
&usedPolicyNameNum, &usedManifestNameNum),
usedPolicyNameNum, usedManifestNameNum = getConfigurationPolicyName(policyConf, i,
usedPolicyNameNum, usedManifestNameNum),

But it's kind of long, maybe it's not better 😓

Copy link
Member

@dhaiducek dhaiducek left a 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.

docs/policygenerator-reference.yaml Outdated Show resolved Hide resolved
internal/utils.go Outdated Show resolved Hide resolved
internal/utils.go Outdated Show resolved Hide resolved
Comment on lines 338 to 352
// 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
}
Copy link
Member

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)

Suggested change
// 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
}

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

internal/utils.go Outdated Show resolved Hide resolved
internal/utils.go Outdated Show resolved Hide resolved
internal/utils.go Outdated Show resolved Hide resolved
@mprahl
Copy link
Member

mprahl commented Aug 2, 2024

/hold for other reviews

Copy link
Member

@dhaiducek dhaiducek left a 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.

Copy link

openshift-ci bot commented Aug 2, 2024

[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:
  • OWNERS [dhaiducek,mprahl,yiraeChristineKim]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@yiraeChristineKim
Copy link
Contributor Author

/unhold

@openshift-merge-bot openshift-merge-bot bot merged commit dd1f91f into open-cluster-management-io:main Aug 5, 2024
4 checks passed
@yiraeChristineKim
Copy link
Contributor Author

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.
The Fix version is 2.12 so we don't need to backport Thanks for your comment. I haven't thought about a "same name" case. Good Catch!!
Should we give the use a warning message when manifests[].name and policies[].name are same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants