Skip to content

(bugfix): make k8s 1.25 validation logic check api group before issuing a warning - #274

Merged
openshift-merge-robot merged 2 commits into
operator-framework:masterfrom
everettraven:bugfix/k8s-1.25-validation
Dec 21, 2022
Merged

(bugfix): make k8s 1.25 validation logic check api group before issuing a warning#274
openshift-merge-robot merged 2 commits into
operator-framework:masterfrom
everettraven:bugfix/k8s-1.25-validation

Conversation

@everettraven

Copy link
Copy Markdown
Contributor

Description of Change

This PR updates the k8s 1.25 validation logic and the associated test cases to verify if any of the apiGroups defined in an RBAC PolicyRule has a potential deprecation. If it finds one it will check a combination of the apiGroup and all resources defined in the PolicyRule (i.e apiGroup/resource) to see if any of these combinations results in a deprecated API - if so it returns a warning.

Motivation for Change

There was a bug in the validation logic where it was issuing a warning even if the API group the resource belonged to had not been deprecated.

to now check the apiGroup/resource to determine if an api is deprecated.

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
@openshift-ci
openshift-ci Bot requested review from benluddy and exdx December 12, 2022 14:10
@everettraven

Copy link
Copy Markdown
Contributor Author

/cc @joelanford @oceanc80 @grokspawn

Comment thread pkg/validation/internal/removed_apis.go Outdated
// check a combination of apiGroup/resource for all
// the resources to see if any match the deprecated apis
for _, res := range rule.Resources {
if _, ok := resInCsvCrds[res]; ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this should be !ok to early out if we don't find the deprecated api in the set of CRs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that is actually a check that’s saying “if this resource is already covered by one that’s listed in the CSV as something the operator uses, then that’s a more reliable check, so skip this check”

This might be something we want to add a comment for since it isn't immediately obvious why we'd be bailing out when we find an RBAC rule for a resource within a deprecated API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Taking a look at this, I think it could really go either way. The intention behind this section is exactly what @joelanford mentioned.

I think we could either add a comment or adopt the recommendation by @oceanc80 and remove the continue statement within the block.

i.e go from:

for _, res := range rule.Resources {
	if _, ok := resInCsvCrds[res]; ok {
		continue
	}
       warnIfDeprecated(schema.GroupResource{Group: apiGroup, Resource: res}, fmt.Sprintf("ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.%s[%d].Rules[%d]", permField, i, j))
}

to:

for _, res := range rule.Resources {
	if _, ok := resInCsvCrds[res]; !ok {
            warnIfDeprecated(schema.GroupResource{Group: apiGroup, Resource: res}, fmt.Sprintf("ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.%s[%d].Rules[%d]", permField, i, j))
	}
}

Technically saves us a line of code and if it feels more readable that way I am happy to change it

Comment thread pkg/validation/internal/removed_apis.go Outdated
Comment thread pkg/validation/internal/removed_apis.go Outdated
}
}

apiGroupHasDeprecation := func(group string) bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question here. Can we make this a map[string]struct{} (or use sets.String from k8s.io/apimachinery)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After adding maps to resolve your previous comment, I ended up removing this function definition as the map used by warnIfDeprecated has the schema.GroupResource as a key. If the given schema.GroupResource doesn't match any of the keys it doesn't warn.

I think the only downside to having removed this function is that now it always runs the loop to create a schema.GroupResource and verify it instead of only if the group has a deprecated api. If this is something we are concerned about I can re-implement this function.

@joelanford @oceanc80 WDYT?

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
@theishshah

Copy link
Copy Markdown

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Dec 20, 2022
@theishshah

Copy link
Copy Markdown

/approve

1 similar comment
@kevinrizza

Copy link
Copy Markdown
Member

/approve

@openshift-ci

openshift-ci Bot commented Dec 21, 2022

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: everettraven, kevinrizza, theishshah

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 21, 2022
@openshift-merge-robot
openshift-merge-robot merged commit f1b7296 into operator-framework:master Dec 21, 2022
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. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants