Skip to content
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
4 changes: 4 additions & 0 deletions config/openshift/base/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ spec:
value: tekton.dev/operator
- name: VERSION
value: "devel"
# OLM channel of this operator. When set, the MultiKueue plugin installs
# OpenShift Pipelines on worker clusters from this channel.
- name: PIPELINES_OPERATOR_CHANNEL
value: ""
- name: AUTOINSTALL_COMPONENTS
valueFrom:
configMapKeyRef:
Expand Down
8 changes: 8 additions & 0 deletions docs/TektonKueue.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ variables. For standalone TektonKueue, use `spec.options.deployments`.
`KUEUE_NAMESPACE` changes Secret placement only; the bundled external Kueue RBAC
binding still targets `openshift-kueue-operator`.

The plugin installs OpenShift Pipelines on a worker that has no Subscription for
it. When the operator has the `PIPELINES_OPERATOR_CHANNEL` environment variable,
it passes the value to the plugin, which uses that channel for these workers.
OpenShift Pipelines sets it to its own channel, so these workers get the hub's
version. Without it, the plugin uses the channel defined by its bundled release.
Workers that already run OpenShift Pipelines keep their version. The deployment
options above can override the channel.

Operator deployments can override the plugin image with
`IMAGE_MULTIKUEUE_PLUGIN_CONTROLLER`. The plugin also uses the existing
`TEKTON_REGISTRY_OVERRIDE` mechanism.
Expand Down
33 changes: 30 additions & 3 deletions pkg/reconciler/openshift/tektonkueue/multikueue_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package tektonkueue

import (
"context"
"os"

mf "github.com/manifestival/manifestival"
"github.com/pkg/errors"
Expand All @@ -26,12 +27,20 @@ import (
"github.com/tektoncd/operator/pkg/reconciler/openshift"
occommon "github.com/tektoncd/operator/pkg/reconciler/openshift/common"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"knative.dev/pkg/logging"
)

const multiKueuePluginSet = "multikueue-plugin"
const (
multiKueuePluginSet = "multikueue-plugin"

// pipelinesOperatorChannelEnv names the OLM channel of this operator. It is
// passed on to the plugin, which installs OpenShift Pipelines on worker
// clusters from this channel.
pipelinesOperatorChannelEnv = "PIPELINES_OPERATOR_CHANNEL"
)

// reconcilePlugin installs the plugin. Until it is ready, it returns a requeue
// error that is wrapped with the reason.
Expand All @@ -49,12 +58,26 @@ func (oe openshiftExtension) reconcilePlugin(ctx context.Context, kueue *v1alpha
return errors.Wrapf(v1alpha1.REQUEUE_EVENT_AFTER, "ACM plugin requires API %s", gv)
}
}
if err := oe.installerSetClient.CustomSet(ctx, kueue, multiKueuePluginSet, &oe.manifest, transformPlugin, nil); err != nil {
if err := oe.installerSetClient.CustomSet(ctx, withPluginHashInput(kueue), multiKueuePluginSet, &oe.manifest, transformPlugin, nil); err != nil {
return errors.Wrap(err, "ACM plugin installation is not ready")
}
return nil
}

// withPluginHashInput adds the channel from the operator's environment to the
// hash of the plugin installer set. The set is updated only when that hash
// changes, and the channel is not part of the TektonKueue spec.
func withPluginHashInput(kueue *v1alpha1.TektonKueue) *v1alpha1.TektonKueue {
channel := os.Getenv(pipelinesOperatorChannelEnv)
if channel == "" {
return kueue
}
kueue = kueue.DeepCopy()
metav1.SetMetaDataAnnotation(&kueue.ObjectMeta, v1alpha1.PlatformDataHashKey,
kueue.Annotations[v1alpha1.PlatformDataHashKey]+pipelinesOperatorChannelEnv+"="+channel)
return kueue
}

// cleanupPlugin removes the plugin installer set. It requeues until the set is
// gone, and also when the removal fails, so that it is retried.
func (oe openshiftExtension) cleanupPlugin(ctx context.Context) error {
Expand Down Expand Up @@ -95,10 +118,14 @@ func transformPlugin(ctx context.Context, manifest *mf.Manifest, comp v1alpha1.T
return nil, err
}
images := common.ImageRegistryDomainOverride(common.ToLowerCaseKeys(common.ImagesFromEnv(common.MultiKueuePluginImagePrefix)))
env := []corev1.EnvVar{{Name: "KUEUE_NAMESPACE", Value: openshift.KueueNameSpace}}
if channel := os.Getenv(pipelinesOperatorChannelEnv); channel != "" {
env = append(env, corev1.EnvVar{Name: pipelinesOperatorChannelEnv, Value: channel})
}
if err := common.Transform(ctx, &updated, comp,
common.InjectOperandNameLabelOverwriteExisting(v1alpha1.TektonKueueResourceName),
common.DeploymentImages(images),
common.DeploymentEnvVars([]corev1.EnvVar{{Name: "KUEUE_NAMESPACE", Value: openshift.KueueNameSpace}}),
common.DeploymentEnvVars(env),
occommon.RemoveRunAsUser(), occommon.RemoveRunAsGroup(),
); err != nil {
return nil, err
Expand Down
108 changes: 98 additions & 10 deletions pkg/reconciler/openshift/tektonkueue/multikueue_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ func pluginDiscovery() *discoveryfake.FakeDiscovery {
return d
}

func markSetReady(set *v1alpha1.TektonInstallerSet) {
set.Status.MarkCRDsInstalled()
set.Status.MarkNamespaceScopedResourcesInstalled()
set.Status.MarkClustersScopedResourcesInstalled()
set.Status.MarkDeploymentsAvailable()
set.Status.MarkStatefulSetReady()
set.Status.MarkDaemonSetReady()
set.Status.MarkControllerReady()
set.Status.MarkWebhookReady()
set.Status.MarkAllDeploymentsReady()
set.Status.MarkJobsInstalled()
}

// pluginEnv returns the env of the plugin container in the transformed manifest.
func pluginEnv(t *testing.T, resources []unstructured.Unstructured) map[string]string {
t.Helper()
for _, obj := range resources {
if obj.GetKind() != "Deployment" {
continue
}
deployment := &appsv1.Deployment{}
assert.NilError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, deployment))
env := map[string]string{}
for _, e := range deployment.Spec.Template.Spec.Containers[0].Env {
env[e.Name] = e.Value
}
return env
}
t.Fatal("no Deployment in the plugin manifest")
return nil
}

func TestPluginLifecycle(t *testing.T) {
ctx := t.Context()
kueue := pluginKueue()
Expand All @@ -87,16 +119,7 @@ func TestPluginLifecycle(t *testing.T) {
set := sets.Items[0]
assert.Equal(t, set.OwnerReferences[0].UID, kueue.UID)
assert.Equal(t, set.Labels[v1alpha1.InstallerSetType], "custom-multikueue-plugin")
set.Status.MarkCRDsInstalled()
set.Status.MarkNamespaceScopedResourcesInstalled()
set.Status.MarkClustersScopedResourcesInstalled()
set.Status.MarkDeploymentsAvailable()
set.Status.MarkStatefulSetReady()
set.Status.MarkDaemonSetReady()
set.Status.MarkControllerReady()
set.Status.MarkWebhookReady()
set.Status.MarkAllDeploymentsReady()
set.Status.MarkJobsInstalled()
markSetReady(&set)
_, err = isClient.Update(ctx, &set, metav1.UpdateOptions{})
assert.NilError(t, err)
assert.NilError(t, oe.PreReconcile(ctx, kueue))
Expand Down Expand Up @@ -228,3 +251,68 @@ func TestPluginTransforms(t *testing.T) {
})
}
}

// The plugin installs OpenShift Pipelines on workers from the operator's channel.
// Without it, the plugin uses its own default; deployment options override it.
func TestPluginPipelinesChannel(t *testing.T) {
for _, tt := range []struct {
name, channel, option, want string
}{
{name: "unset"},
{name: "set", channel: "pipelines-1.25", want: "pipelines-1.25"},
{name: "option overrides", channel: "pipelines-1.25", option: "pipelines-1.24", want: "pipelines-1.24"},
} {
t.Run(tt.name, func(t *testing.T) {
t.Setenv(pipelinesOperatorChannelEnv, tt.channel)
kueue := pluginKueue()
if tt.option != "" {
kueue.Spec.Options.Deployments = map[string]appsv1.Deployment{
"pipelines-multikueue-plugin-controller": {Spec: appsv1.DeploymentSpec{Template: corev1.PodTemplateSpec{Spec: corev1.PodSpec{
Containers: []corev1.Container{{Name: "controller", Env: []corev1.EnvVar{{Name: pipelinesOperatorChannelEnv, Value: tt.option}}}},
}}}},
}
}
m := pluginManifest(t)
transformed, err := transformPlugin(context.Background(), &m, kueue)
assert.NilError(t, err)
env := pluginEnv(t, transformed.Resources())
channel, ok := env[pipelinesOperatorChannelEnv]
assert.Equal(t, ok, tt.want != "")
assert.Equal(t, channel, tt.want)
assert.Equal(t, env["KUEUE_NAMESPACE"], "openshift-kueue-operator")
})
}
}

// The channel is not part of the TektonKueue spec, but a change of it must still
// update the plugin set.
func TestPluginChannelChangeUpdatesSet(t *testing.T) {
t.Setenv(pipelinesOperatorChannelEnv, "")
ctx := t.Context()
kueue := pluginKueue()
isClient := isfake.NewFakeISClient()
oe := openshiftExtension{
manifest: pluginManifest(t), discovery: pluginDiscovery(),
installerSetClient: client.NewInstallerSetClient(isClient, "v1", "plugin", v1alpha1.KindTektonKueue, nil),
}
assert.ErrorIs(t, oe.PreReconcile(ctx, kueue), v1alpha1.REQUEUE_EVENT_AFTER)
sets, err := isClient.List(ctx, metav1.ListOptions{})
assert.NilError(t, err)
set := sets.Items[0]
markSetReady(&set)
_, err = isClient.Update(ctx, &set, metav1.UpdateOptions{})
assert.NilError(t, err)
assert.NilError(t, oe.PreReconcile(ctx, kueue))

for _, channel := range []string{"pipelines-1.25", "pipelines-1.26", ""} {
t.Setenv(pipelinesOperatorChannelEnv, channel)
_ = oe.PreReconcile(ctx, kueue)
sets, err = isClient.List(ctx, metav1.ListOptions{})
assert.NilError(t, err)
assert.Equal(t, len(sets.Items), 1)
assert.Equal(t, sets.Items[0].Name, set.Name, "the set is updated, not replaced")
assert.Equal(t, pluginEnv(t, sets.Items[0].Spec.Manifests)[pipelinesOperatorChannelEnv], channel)
}
// The TektonKueue itself is not changed.
assert.Equal(t, len(kueue.Annotations), 0)
}
Loading