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

Add certification-component-id flag #1222

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bcrochet
Copy link
Contributor

@bcrochet bcrochet commented Dec 9, 2024

This flag deprecates the certification-project-id flag. The field has been changed on the server side, and in certification documentation.

Fixes #1185

@openshift-ci openshift-ci bot requested review from acornett21 and jomkz December 9, 2024 16:54
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 9, 2024
@dcibot
Copy link

dcibot commented Dec 9, 2024

@bcrochet bcrochet force-pushed the fixes/1185 branch 2 times, most recently from 36ccf2f to 8de58b7 Compare December 10, 2024 14:53
@coveralls
Copy link

coveralls commented Dec 10, 2024

Coverage Status

coverage: 84.661% (+0.04%) from 84.619%
when pulling 77ac701 on bcrochet:fixes/1185
into fd13126 on redhat-openshift-ecosystem:main.

@dcibot
Copy link

dcibot commented Dec 10, 2024

@acornett21
Copy link
Contributor

/test 4.17-e2e

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 10, 2024
Copy link

openshift-ci bot commented Dec 10, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acornett21, bcrochet

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 [acornett21,bcrochet]

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

@dcibot
Copy link

dcibot commented Dec 10, 2024

This flag deprecates the certification-project-id flag. The field has
been changed on the server side, and in certification documentation.

Fixes redhat-openshift-ecosystem#1185

Signed-off-by: Brad P. Crochet <[email protected]>
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 10, 2024
Copy link

openshift-ci bot commented Dec 10, 2024

New changes are detected. LGTM label has been removed.

@dcibot
Copy link

dcibot commented Dec 11, 2024

@bcrochet
Copy link
Contributor Author

/test 4.17-e2e

Copy link
Contributor

@komish komish left a comment

Choose a reason for hiding this comment

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

Couple of notes left.

Comment on lines +91 to +102
_ = flags.MarkDeprecated("certification-project-id", "please use --certification-component-id instead")

// Use a bound package-level var here. We are going to leave the rest of the code
// using the Viper id of 'certification_project_id' in order to minimize changes
// in the overall code base.
// When --certification-project-id is fully removed, this should become bound in Viper
flags.StringVar(&componentID, "certification-component-id", "", fmt.Sprintf("Certification component ID from connect.redhat.com/component/view/{certification-component-id}/images\n"+
"URL paramater. This value may differ from the component PID on the overview page. (env: PFLT_CERTIFICATION_COMPONENT_ID)"))
// Here, we are forcing an env binding, so we can check that later. This should also
// be moved to "automatic" once the old project id is removed
_ = viper.BindEnv("certification_component_id")
checkContainerCmd.MarkFlagsMutuallyExclusive("certification-project-id", "certification-component-id")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused. Why not just bind this to viper now? It'll be bound at a different endpoint anyway, and you can resolve the two in the places you need, such as in runtime.NewConfigFrom?

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 try a bunch of different permutations of all this, and this seemed to be the path of least resistance. It's been a bit since I looked at it, so I can't give you a full explanation right now. :)

Comment on lines +128 to 133
// DEPRECATED: Use WithCertificationProject instead
// WithCertificationProject adds the project's id and pyxis token to the check
// allowing for the project's metadata to change the certification (if necessary).
// An example might be the Scratch or Privileged flags on a project allowing for
// the corresponding policy to be executed.
func WithCertificationProject(id, token string) Option {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// DEPRECATED: Use WithCertificationProject instead
// WithCertificationProject adds the project's id and pyxis token to the check
// allowing for the project's metadata to change the certification (if necessary).
// An example might be the Scratch or Privileged flags on a project allowing for
// the corresponding policy to be executed.
func WithCertificationProject(id, token string) Option {
// WithCertificationProject adds the project's id and pyxis token to the check
// allowing for the project's metadata to change the certification (if necessary).
// An example might be the Scratch or Privileged flags on a project allowing for
// the corresponding policy to be executed.
//
// Deprecated: Use WithCertificationComponent instead
func WithCertificationProject(id, token string) Option {

Writing Deprecated (over DEPRECATED) seems to correctly trigger staticcheck when linting. Also, placing it at the end (or, potentially just separated by one blank comment link) makes staticcheck report the suggestion correctly. I wouldn't think it matters, but Godoc specifies the Title Case here.

Also note that the statement is saying to use the same function it's deprecating. Should read "use WithCertificationComponent instead".

Finally, I see two places where this is called in the project that need updating.

cmd/preflight/cmd/check_container.go:294:3   staticcheck  SA1019: container.WithCertificationProject is deprecated: Use WithCertificationComponent instead 
cmd/preflight/cmd/check_container.go:304:17  staticcheck  SA1019: container.WithCertificationProject is deprecated: Use WithCertificationComponent instead 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good suggestion. I'll implement that.

Comment on lines +237 to +240
// However, if the new env var is set, that's the priority
if viper.IsSet("certification_component_id") {
viper.Set("certification_project_id", viper.GetString("certification_component_id"))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this only necessary because certification_component_id is bound explicitly to env, separate from the global variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct.

Comment on lines +230 to +235
// If the new flag is set, use that
if cmd.Flag("certification-component-id").Changed {
cmd.Flag("certification-project-id").Changed = true
cmd.Flag("certification-component-id").Changed = false
viper.Set("certification_project_id", componentID)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding, this is just "promotion" of the value from one flag to the other, right? And updating their Changed state is required to avoid MutualExclusion from throwing an error?

Semantic & Nit: it reads weird to me that we're feeding the value of the new flag into the old flag. Disregard at will.

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 awkward, but this makes it so that we don't have to go change a bunch of other places that use the project-id verbage. It does seem very awkward.

It occurs to me now to that each of these places that are changed should be marked with a TODO so that they are easier to find later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --certification-component-id as synonym to --certification-project-id
5 participants