diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 8e9c9ed4f36..2e7f49b033b 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -27,7 +27,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/contexts" - "github.com/tektoncd/pipeline/pkg/system" "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" @@ -36,6 +35,7 @@ import ( pkgleaderelection "knative.dev/pkg/leaderelection" "knative.dev/pkg/logging" "knative.dev/pkg/signals" + "knative.dev/pkg/system" "knative.dev/pkg/webhook" "knative.dev/pkg/webhook/certificates" "knative.dev/pkg/webhook/configmaps" @@ -206,7 +206,7 @@ func main() { } // Scope informers to the webhook's namespace instead of cluster-wide - ctx := injection.WithNamespaceScope(signals.NewContext(), system.GetNamespace()) + ctx := injection.WithNamespaceScope(signals.NewContext(), system.Namespace()) // Set up a signal context with our webhook options ctx = webhook.WithOptions(ctx, webhook.Options{ diff --git a/pkg/pod/creds_init_test.go b/pkg/pod/creds_init_test.go index 2efb2f87f43..321fafa2427 100644 --- a/pkg/pod/creds_init_test.go +++ b/pkg/pod/creds_init_test.go @@ -22,7 +22,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/config" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" @@ -30,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" fakek8s "k8s.io/client-go/kubernetes/fake" logtesting "knative.dev/pkg/logging/testing" + "knative.dev/pkg/system" ) const ( @@ -223,7 +223,7 @@ func TestCheckGitSSHSecret(t *testing.T) { }{{ desc: "require known_hosts but secret does not include known_hosts", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagRequireKnownHosts: "true", }, @@ -246,7 +246,7 @@ func TestCheckGitSSHSecret(t *testing.T) { }, { desc: "require known_hosts and secret includes known_hosts", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagRequireKnownHosts: "true", }, @@ -268,7 +268,7 @@ func TestCheckGitSSHSecret(t *testing.T) { }, { desc: "not require known_hosts", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagRequireKnownHosts: "false", }, diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 99737e876ae..15798943166 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -30,7 +30,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/pipeline/pkg/version" "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" @@ -39,6 +38,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fakek8s "k8s.io/client-go/kubernetes/fake" logtesting "knative.dev/pkg/logging/testing" + "knative.dev/pkg/system" + + _ "knative.dev/pkg/system/testing" // Setup system.Namespace() ) var ( @@ -1178,7 +1180,7 @@ script-heredoc-randomly-generated-78c5n store := config.NewStore(logtesting.TestLogger(t)) store.OnConfigChanged( &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: c.featureFlags, }, ) @@ -1284,14 +1286,14 @@ func TestShouldOverrideHomeEnv(t *testing.T) { }{{ description: "Default behaviour: A missing disable-home-env-overwrite flag should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: true, }, { description: "Setting disable-home-env-overwrite to false should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableHomeEnvKey: "false", }, @@ -1300,7 +1302,7 @@ func TestShouldOverrideHomeEnv(t *testing.T) { }, { description: "Setting disable-home-env-overwrite to true should result in false", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableHomeEnvKey: "true", }, @@ -1325,14 +1327,14 @@ func TestShouldOverrideWorkingDir(t *testing.T) { }{{ description: "Default behaviour: A missing disable-working-directory-overwrite flag should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: true, }, { description: "Setting disable-working-directory-overwrite to false should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableWorkingDirKey: "false", }, @@ -1341,7 +1343,7 @@ func TestShouldOverrideWorkingDir(t *testing.T) { }, { description: "Setting disable-working-directory-overwrite to true should result in false", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableWorkingDirKey: "true", }, @@ -1374,7 +1376,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Default behavior with sidecars present: Ready annotation not set on pod create", sidecars: []v1beta1.Sidecar{sd}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: false, @@ -1382,7 +1384,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Default behavior with no sidecars present: Ready annotation not set on pod create", sidecars: []v1beta1.Sidecar{}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: false, @@ -1390,7 +1392,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Setting running-in-environment-with-injected-sidecars to true with sidecars present results in false", sidecars: []v1beta1.Sidecar{sd}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureInjectedSidecar: "true", }, @@ -1400,7 +1402,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Setting running-in-environment-with-injected-sidecars to true with no sidecars present results in false", sidecars: []v1beta1.Sidecar{}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureInjectedSidecar: "true", }, @@ -1410,7 +1412,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Setting running-in-environment-with-injected-sidecars to false with sidecars present results in false", sidecars: []v1beta1.Sidecar{sd}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureInjectedSidecar: "false", }, @@ -1420,7 +1422,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Setting running-in-environment-with-injected-sidecars to false with no sidecars present results in true", sidecars: []v1beta1.Sidecar{}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureInjectedSidecar: "false", }, diff --git a/pkg/reconciler/pipelinerun/affinity_assistant_test.go b/pkg/reconciler/pipelinerun/affinity_assistant_test.go index df3c5d94680..c943290f490 100644 --- a/pkg/reconciler/pipelinerun/affinity_assistant_test.go +++ b/pkg/reconciler/pipelinerun/affinity_assistant_test.go @@ -24,12 +24,14 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/system" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fakek8s "k8s.io/client-go/kubernetes/fake" logtesting "knative.dev/pkg/logging/testing" + "knative.dev/pkg/system" + + _ "knative.dev/pkg/system/testing" // Setup system.Namespace() ) // TestCreateAndDeleteOfAffinityAssistant tests to create and delete an Affinity Assistant @@ -171,7 +173,7 @@ func TestThatCleanupIsAvoidedIfAssistantIsDisabled(t *testing.T) { } configMap := &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableAffinityAssistantKey: "true", }, @@ -203,14 +205,14 @@ func TestDisableAffinityAssistant(t *testing.T) { }{{ description: "Default behaviour: A missing disable-affinity-assistant flag should result in false", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: false, }, { description: "Setting disable-affinity-assistant to false should result in false", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableAffinityAssistantKey: "false", }, @@ -219,7 +221,7 @@ func TestDisableAffinityAssistant(t *testing.T) { }, { description: "Setting disable-affinity-assistant to true should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableAffinityAssistantKey: "true", }, diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 3cd461c2a11..a858f719d7d 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -41,7 +41,6 @@ import ( "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" taskrunresources "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/pipeline/test" "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" @@ -63,6 +62,9 @@ import ( "knative.dev/pkg/logging" logtesting "knative.dev/pkg/logging/testing" "knative.dev/pkg/reconciler" + "knative.dev/pkg/system" + + _ "knative.dev/pkg/system/testing" // Setup system.Namespace() ) var ( @@ -109,25 +111,25 @@ func ensureConfigurationConfigMapsExist(d *test.Data) { } if !defaultsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !featureFlagsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !artifactBucketExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !artifactPVCExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } @@ -141,7 +143,7 @@ func getPipelineRunController(t *testing.T, d test.Data) (test.Assets, func()) { ctx, cancel := context.WithCancel(ctx) ensureConfigurationConfigMapsExist(&d) c, informers := test.SeedTestData(t, ctx, d) - configMapWatcher := cminformer.NewInformedWatcher(c.Kube, system.GetNamespace()) + configMapWatcher := cminformer.NewInformedWatcher(c.Kube, system.Namespace()) ctl := NewController(namespace, images)(ctx, configMapWatcher) @@ -595,7 +597,7 @@ func TestReconcile_CustomTask(t *testing.T) { cms := []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "enable-custom-tasks": "true", }, @@ -1780,7 +1782,7 @@ func TestReconcileCustomTasksWithDifferentServiceAccounts(t *testing.T) { cms := []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "enable-custom-tasks": "true", }, @@ -2142,7 +2144,7 @@ func TestReconcileCustomTasksWithTaskRunSpec(t *testing.T) { cms := []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "enable-custom-tasks": "true", }, @@ -3412,7 +3414,7 @@ func TestReconcileOutOfSyncPipelineRun(t *testing.T) { cms := []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "enable-custom-tasks": "true", }, @@ -4413,7 +4415,7 @@ func TestReconcile_CloudEvents(t *testing.T) { } cms := []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-cloud-events-sink": "http://synk:8080", }, @@ -4638,7 +4640,7 @@ func TestReconcile_RemotePipelineRef(t *testing.T) { } cms := []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "enable-tekton-oci-bundles": "true", }, diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 0b1e853209c..7ae38ee2c4d 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -40,7 +40,6 @@ import ( "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" "github.com/tektoncd/pipeline/pkg/reconciler/volumeclaim" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/pipeline/pkg/version" "github.com/tektoncd/pipeline/pkg/workspace" "github.com/tektoncd/pipeline/test" @@ -61,7 +60,11 @@ import ( "knative.dev/pkg/controller" "knative.dev/pkg/kmeta" "knative.dev/pkg/logging" + pkgreconciler "knative.dev/pkg/reconciler" + "knative.dev/pkg/system" + + _ "knative.dev/pkg/system/testing" // Setup system.Namespace() ) const ( @@ -256,25 +259,25 @@ func ensureConfigurationConfigMapsExist(d *test.Data) { } if !defaultsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !featureFlagsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !artifactBucketExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !artifactPVCExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } @@ -288,7 +291,7 @@ func getTaskRunController(t *testing.T, d test.Data) (test.Assets, func()) { ctx, cancel := context.WithCancel(ctx) ensureConfigurationConfigMapsExist(&d) c, informers := test.SeedTestData(t, ctx, d) - configMapWatcher := cminformer.NewInformedWatcher(c.Kube, system.GetNamespace()) + configMapWatcher := cminformer.NewInformedWatcher(c.Kube, system.Namespace()) ctl := NewController(namespace, images)(ctx, configMapWatcher) if err := configMapWatcher.Start(ctx.Done()); err != nil { @@ -414,7 +417,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) { Tasks: []*v1beta1.Task{simpleTask, saTask}, ConfigMaps: []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-service-account": defaultSAName, "default-timeout-minutes": "60", @@ -696,7 +699,7 @@ func TestReconcile_FeatureFlags(t *testing.T) { names.TestingSeed() d.ConfigMaps = []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ tc.featureFlag: "true", }, @@ -782,7 +785,7 @@ func TestReconcile_CloudEvents(t *testing.T) { names.TestingSeed() d.ConfigMaps = []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-cloud-events-sink": "http://synk:8080", }, @@ -2596,7 +2599,7 @@ func TestReconcileValidDefaultWorkspace(t *testing.T) { } d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-task-run-workspace-binding": "emptyDir: {}", }, @@ -2652,7 +2655,7 @@ func TestReconcileInvalidDefaultWorkspace(t *testing.T) { } d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-task-run-workspace-binding": "emptyDir == {}", }, @@ -2719,7 +2722,7 @@ func TestReconcileValidDefaultWorkspaceOmittedOptionalWorkspace(t *testing.T) { } d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-task-run-workspace-binding": "emptyDir: {}", }, diff --git a/pkg/system/names.go b/pkg/system/names.go deleted file mode 100644 index f4c31a2867f..00000000000 --- a/pkg/system/names.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package system - -import "os" - -const ( - DefaultNamespace = "tekton-pipelines" - SystemNamespaceEnvVar = "SYSTEM_NAMESPACE" -) - -// GetNamespace holds the K8s namespace where our system components run. -func GetNamespace() string { - systemNamespace := os.Getenv(SystemNamespaceEnvVar) - if systemNamespace == "" { - return DefaultNamespace - } - return systemNamespace -} diff --git a/pkg/system/names_test.go b/pkg/system/names_test.go deleted file mode 100644 index dbc14345a91..00000000000 --- a/pkg/system/names_test.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package system - -import ( - "os" - "testing" -) - -func TestGetNamespace(t *testing.T) { - testcases := []struct { - envVar string - expectEnvVar string - }{{ - envVar: "", - expectEnvVar: DefaultNamespace, - }, { - envVar: "test", - expectEnvVar: "test", - }} - - value := os.Getenv(SystemNamespaceEnvVar) - defer func() { os.Setenv(SystemNamespaceEnvVar, value) }() - - for _, ts := range testcases { - if err := os.Setenv(SystemNamespaceEnvVar, ts.envVar); err != nil { - t.Fatalf("Failed to set ENV: %v", err) - } - - if got, want := GetNamespace(), ts.expectEnvVar; got != want { - t.Fatalf("Invalid namespace: got: %v, want: %v", got, want) - } - } -} diff --git a/test/custom_task_test.go b/test/custom_task_test.go index 4dd317f643b..530e90b6669 100644 --- a/test/custom_task_test.go +++ b/test/custom_task_test.go @@ -27,12 +27,12 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/pkg/system" knativetest "knative.dev/pkg/test" ) @@ -206,7 +206,7 @@ func TestCustomTask(t *testing.T) { } func skipIfCustomTasksDisabled(ctx context.Context, t *testing.T, c *clients, namespace string) { - featureFlagsCM, err := c.KubeClient.CoreV1().ConfigMaps(system.GetNamespace()).Get(ctx, config.GetFeatureFlagsConfigName(), metav1.GetOptions{}) + featureFlagsCM, err := c.KubeClient.CoreV1().ConfigMaps(system.Namespace()).Get(ctx, config.GetFeatureFlagsConfigName(), metav1.GetOptions{}) if err != nil { t.Fatalf("Failed to get ConfigMap `%s`: %s", config.GetFeatureFlagsConfigName(), err) } diff --git a/test/tektonbundles_test.go b/test/tektonbundles_test.go index f8548ab011f..f65a6b6eee7 100644 --- a/test/tektonbundles_test.go +++ b/test/tektonbundles_test.go @@ -40,10 +40,10 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/pod" - "github.com/tektoncd/pipeline/pkg/system" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" + "knative.dev/pkg/system" knativetest "knative.dev/pkg/test" ) @@ -519,7 +519,7 @@ func publishImg(ctx context.Context, t *testing.T, c *clients, namespace string, } func skipIfTektonOCIBundleDisabled(ctx context.Context, t *testing.T, c *clients, namespace string) { - featureFlagsCM, err := c.KubeClient.CoreV1().ConfigMaps(system.GetNamespace()).Get(ctx, config.GetFeatureFlagsConfigName(), metav1.GetOptions{}) + featureFlagsCM, err := c.KubeClient.CoreV1().ConfigMaps(system.Namespace()).Get(ctx, config.GetFeatureFlagsConfigName(), metav1.GetOptions{}) if err != nil { t.Fatalf("Failed to get ConfigMap `%s`: %s", config.GetFeatureFlagsConfigName(), err) }