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: configure StepAction to use conversion webhook #8644

Merged
merged 2 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/300-crds/300-stepaction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1113,3 +1113,11 @@ spec:
- tekton
- tekton-pipelines
scope: Namespaced
conversion:
Copy link
Member

Choose a reason for hiding this comment

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

is it possible to add any tests for this ?
cc @afrittoli

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I checked the conversion reconciler logic, the only idea I can think of right now is to add a test in the e2e/conversion_test to verify whether the CRD's Strategy is set to Webhook. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@waveywaves Could you check d5944bf ? Thx in advance :)

Copy link
Member

Choose a reason for hiding this comment

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

I think the test looks good for now based on how the reconciler in knative is checking for the webhook strategy

strategy: Webhook
webhook:
conversionReviewVersions: ["v1alpha1", "v1beta1"]
clientConfig:
service:
name: tekton-pipelines-webhook
namespace: tekton-pipelines
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.31.4 // indirect
k8s.io/apiextensions-apiserver v0.31.4
k8s.io/gengo v0.0.0-20240404160639-a0386bf69313 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
8 changes: 8 additions & 0 deletions test/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ import (
"github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1beta1"
resolutionversioned "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned"
resolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1"
apixclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
knativetest "knative.dev/pkg/test"
)

// clients holds instances of interfaces for making requests to the Pipeline controllers.
type clients struct {
KubeClient kubernetes.Interface
ApixClient apixclient.Interface

V1beta1PipelineClient v1beta1.PipelineInterface
V1beta1ClusterTaskClient v1beta1.ClusterTaskInterface
Expand Down Expand Up @@ -90,6 +92,12 @@ func newClients(t *testing.T, configPath, clusterName, namespace string) *client
}
c.KubeClient = kubeClient

apixClient, err := apixclient.NewForConfig(cfg)
if err != nil {
t.Fatalf("failed to create apixclient from config file at %s: %s", configPath, err)
}
c.ApixClient = apixClient

cs, err := versioned.NewForConfig(cfg)
if err != nil {
t.Fatalf("failed to create pipeline clientset from config file at %s: %s", configPath, err)
Expand Down
39 changes: 39 additions & 0 deletions test/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1"
"github.com/tektoncd/pipeline/test/parse"
corev1 "k8s.io/api/core/v1"
apixv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
knativetest "knative.dev/pkg/test"
"knative.dev/pkg/test/helpers"
)
Expand Down Expand Up @@ -652,6 +655,42 @@ status:
`
)

// TestCRDConversionStrategy tests if webhook conversion strategy is
// set to versioned CRDs.
func TestCRDConversionStrategy(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()

t.Parallel()

c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
defer tearDown(ctx, t, c, namespace)

kinds := []schema.GroupKind{
v1beta1.Kind("stepactions"),
v1.Kind("tasks"),
v1.Kind("pipelines"),
v1.Kind("taskruns"),
v1.Kind("pipelineruns"),
resolutionv1beta1.Kind("resolutionrequests"),
}
for _, kind := range kinds {
gotCRD, err := c.ApixClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), kind.String(), metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected CRD %s: %s", kind, err)
}

if gotCRD.Spec.Conversion == nil {
t.Errorf("Expected custom resource %q to have conversion strategy", kind)
}
if gotCRD.Spec.Conversion.Strategy != apixv1.WebhookConverter {
t.Errorf("Expected custom resource %q to have conversion strategy %s, got %s", kind, apixv1.WebhookConverter, gotCRD.Spec.Conversion.Strategy)
}
}
}

// TestTaskCRDConversion first creates a v1beta1 Task CRD using v1beta1Clients and
// requests it by v1Clients to compare with v1 if the conversion has been correctly
// executed by the webhook for roundtrip. And then it creates the v1 Task CRD using v1Clients
Expand Down
Loading