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

fix(CNV-29761): ensure that tekton crd exists #567

Merged
merged 1 commit into from Jun 12, 2023
Merged

fix(CNV-29761): ensure that tekton crd exists #567

merged 1 commit into from Jun 12, 2023

Conversation

codingben
Copy link
Member

@codingben codingben commented Jun 7, 2023

What this PR does / why we need it:

Checks if Tekton CRD is installed during Tekton
operands reconciliation and during cleanup
process when listing deprecated ClusterTasks.

Release note:

Ensure Tekton CRD exists during reconciliation and cleanup process.

@kubevirt-bot kubevirt-bot added the dco-signoff: yes Indicates the PR's author has DCO signed all their commits. label Jun 7, 2023
@kubevirt-bot kubevirt-bot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/M release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 7, 2023
@codingben
Copy link
Member Author

@ksimon1 Also proposed similar solution in 9784b47 (no PR yet). IMO, request.CrdList.CrdExists(tektonCrd) will always return false, since we're not watching Tekton CRD.

@codingben
Copy link
Member Author

codingben commented Jun 7, 2023

This PR is related to #566 as the error appears in the same log. From HCO CI:

2023-06-05T15:54:49.852185058Z {"level":"error","ts":"2023-06-05T15:54:49Z","logger":"controller-runtime.source","msg":"if kind is a CRD, it should be installed before calling Start","kind":"VirtualMachine.kubevirt.io","error":"no matches for kind \"VirtualMachine\" in version \"kubevirt.io/v1\"","stacktrace":"sigs.k8s.io/controller-runtime/pkg/source.(*Kind).Start.func1.1\n\t/workspace/vendor/sigs.k8s.io/controller-runtime/pkg/source/source.go:143\nk8s.io/apimachinery/pkg/util/wait.runConditionWithCrashProtectionWithContext\n\t/workspace/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:235\nk8s.io/apimachinery/pkg/util/wait.WaitForWithContext\n\t/workspace/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:662\nk8s.io/apimachinery/pkg/util/wait.poll\n\t/workspace/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:596\nk8s.io/apimachinery/pkg/util/wait.PollImmediateUntilWithContext\n\t/workspace/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:547\nsigs.k8s.io/controller-runtime/pkg/source.(*Kind).Start.func1\n\t/workspace/vendor/sigs.k8s.io/controller-runtime/pkg/source/source.go:136"}
2023-06-05T15:54:54.101717335Z {"level":"error","ts":"2023-06-05T15:54:54Z","msg":"Reconciler error","controller":"ssp","controllerGroup":"ssp.kubevirt.io","controllerKind":"SSP","SSP":{"name":"ssp-kubevirt-hyperconverged","namespace":"kubevirt-hyperconverged"},"namespace":"kubevirt-hyperconverged","name":"ssp-kubevirt-hyperconverged","reconcileID":"88d7bebc-81f4-44d1-b833-6cef9117cdad","error":"no matches for kind \"ClusterTask\" in version \"tekton.dev/v1beta1\"","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:329\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:274\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/workspace/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:235"}

@codingben codingben requested a review from ksimon1 June 8, 2023 08:08
@ksimon1
Copy link
Member

ksimon1 commented Jun 8, 2023

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 8, 2023
@codingben
Copy link
Member Author

/test e2e-single-node-functests

@kubevirt-bot
Copy link
Contributor

@codingben: No presubmit jobs available for kubevirt/ssp-operator@master

In response to this:

/test e2e-single-node-functests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@codingben
Copy link
Member Author

We can also consider #570 as an alternative solution to that potential issue, since listDeprecatedClusterTasks() was moved from Cleanup() to Reconcile().

@codingben
Copy link
Member Author

/test win11-pipeline-example-test

@kubevirt-bot
Copy link
Contributor

@codingben: No presubmit jobs available for kubevirt/ssp-operator@master

In response to this:

/test win11-pipeline-example-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@codingben
Copy link
Member Author

/test win11-pipeline-example-test

@kubevirt-bot
Copy link
Contributor

@codingben: No presubmit jobs available for kubevirt/ssp-operator@master

In response to this:

/test win11-pipeline-example-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@codingben
Copy link
Member Author

Yesterday I've reproduced that error in CNV QE cluster, it happened during CNV product removal process. After I've installed Tekton CRD, it's no longer complained about an error, so I'm pretty sure this is caused by defined ClusterTask in Cleanup().

// Solution to optional Tekton CRD is not implemented yet.
// Until then, do not check if Tekton CRD exists.
//
// if !request.CrdList.CrdExists(tektonCrd) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the reason why not use this check instead of checking if feature gate is enabled? Does it not work?

ClusterTasks should be removed on Cleanup() even if the feature gate is disabled, @ksimon1 is that right?
When Tekton CRD does not exist then there are no ClusterTasks to cleanup.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, if crd does not exists, then there are no tasks / clusterTasks/ pipelines

Copy link
Member Author

Choose a reason for hiding this comment

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

What is the reason why not use this check instead of checking if feature gate is enabled? Does it not work?

We're not watching Tekton CRD, because then it'll throw an error because it thinks it's required CRD and not an optional. Please see #561.

ClusterTasks should be removed on Cleanup() even if the feature gate is disabled, @ksimon1 is that right?

Yes, but then Tekton CRD is required. I assume that if the customer is using TTO, customer likely will have Tekton CRD already installed so the Feature Gate in ssp-operator will be enabled as well.

When Tekton CRD does not exist then there are no ClusterTasks to cleanup.

Yes, but we'll need to have !request.CrdList.CrdExists(tektonCrd) for it, which doesn't work now because we don't have a solution to optional CRDs.

Copy link
Collaborator

@akrejcir akrejcir Jun 12, 2023

Choose a reason for hiding this comment

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

To clarify, CrdList interface watches all CustomResourceDefinition objects in the cluster. The method CrdList.CrdExists() can be used to check if any CRD exists in the cluster.
In this case, we can use it to check if Tekton CRD is present, and only delete ClusterTasks if it is.

We're not watching Tekton CRD, because then it'll throw an error because it thinks it's required CRD and not an optional. Please see #561.

We are not watching objects defined in the Tekton CRD. But we are watching the CRD itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you're absolutely right. Let's use CrdList interface then.

@@ -215,7 +227,7 @@ func (t *tektonTasks) Cleanup(request *common.Request) ([]common.CleanupResult,
func listDeprecatedClusterTasks(request *common.Request) ([]pipeline.ClusterTask, error) {
deprecatedClusterTasks := &pipeline.ClusterTaskList{}
err := request.Client.List(request.Context, deprecatedClusterTasks, &client.MatchingLabels{
common.AppKubernetesManagedByLabel: common.AppKubernetesManagedByValue,
common.AppKubernetesManagedByLabel: common.TektonAppKubernetesManagedByValue,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it makes sense to check for both values, please use In operation on the label selector:

	labelRequirement, err := labels.NewRequirement(common.AppKubernetesManagedByLabel,
		selection.In, []string{common.TektonAppKubernetesManagedByValue, common.AppKubernetesManagedByValue})
	if err != nil {
		panic(err)
	}

	err = request.Client.List(request.Context, deprecatedClusterTasks, &client.MatchingLabelsSelector{
		Selector: labels.NewSelector().Add(*labelRequirement),
	})

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice piece of code! Thanks :) ssp-operator will not deploy ClusterTasks (just Tasks) as it was deprecated, only TTO was deploying ClusterTasks, so it makes sense to just use common.TektonAppKubernetesManagedByValue.

@codingben codingben marked this pull request as draft June 12, 2023 09:36
@kubevirt-bot kubevirt-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. and removed lgtm Indicates that a PR is ready to be merged. labels Jun 12, 2023
@codingben codingben changed the title fix(CNV-29436): tekton enabled during cleanup fix(CNV-29436): ensure that tekton crd exists Jun 12, 2023
@codingben codingben marked this pull request as ready for review June 12, 2023 09:46
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 12, 2023
@codingben codingben requested a review from akrejcir June 12, 2023 09:46
@ksimon1
Copy link
Member

ksimon1 commented Jun 12, 2023

/lgtm

@kubevirt-bot kubevirt-bot added lgtm Indicates that a PR is ready to be merged. and removed lgtm Indicates that a PR is ready to be merged. labels Jun 12, 2023
@codingben codingben changed the title fix(CNV-29436): ensure that tekton crd exists fix: ensure that tekton crd exists Jun 12, 2023
@akrejcir
Copy link
Collaborator

In the Cleanup() methods for both operands. I think it will fail when trying to cleanup Tasks and Pipelines. You also need to add them to the if request.CrdList.CrdExists(tektonCrd) {} block.

Checks if Tekton CRD is installed during Tekton
operands reconciliation and during cleanup
process when listing deprecated ClusterTasks.

Signed-off-by: Ben Oukhanov <boukhanov@redhat.com>
@codingben codingben changed the title fix: ensure that tekton crd exists fix(CNV-29761): ensure that tekton crd exists Jun 12, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jun 12, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codingben
Copy link
Member Author

codingben commented Jun 12, 2023

@akrejcir Yep, better to be safe than to be worried. Done.

@akrejcir
Copy link
Collaborator

Thanks.
/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 12, 2023
@akrejcir
Copy link
Collaborator

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: akrejcir

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 12, 2023
@codingben
Copy link
Member Author

/test win2k22-pipeline-example-test

@kubevirt-bot
Copy link
Contributor

@codingben: No presubmit jobs available for kubevirt/ssp-operator@master

In response to this:

/test win2k22-pipeline-example-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@kubevirt-bot kubevirt-bot merged commit 42be785 into kubevirt:master Jun 12, 2023
13 checks passed
@codingben codingben deleted the CNV-29436 branch June 28, 2023 14:22
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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants