diff --git a/CHANGELOG.md b/CHANGELOG.md index 94f1a769c0..24caedf447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,6 @@ - Move helm module into a directory (https://github.com/pulumi/pulumi-kubernetes/pull/512) - Move yaml module into a directory (https://github.com/pulumi/pulumi-kubernetes/pull/513) -- Put all resources in specified provider namespace (https://github.com/pulumi/pulumi-kubernetes/pull/506) ### Bug fixes diff --git a/pkg/clients/clients.go b/pkg/clients/clients.go index 9fbf910356..007b45a472 100644 --- a/pkg/clients/clients.go +++ b/pkg/clients/clients.go @@ -86,7 +86,7 @@ func (dcs *DynamicClientSet) ResourceClient(gvk schema.GroupVersionKind, namespa } // For namespaced Kinds, create a namespaced client. If no namespace is provided, use the "default" namespace. - namespaced, err := dcs.NamespacedKind(gvk) + namespaced, err := dcs.namespaced(gvk) if err != nil { return nil, err } @@ -132,15 +132,10 @@ func (dcs *DynamicClientSet) gvkForKind(kind kinds.Kind) (*schema.GroupVersionKi return nil, fmt.Errorf("failed to find gvk for Kind: %q", kind) } -func (dcs *DynamicClientSet) NamespacedKind(gvk schema.GroupVersionKind) (bool, error) { - gv := gvk.GroupVersion().String() - if strings.Contains(gv, "core/v1") { - gv = "v1" - } - - resourceList, err := dcs.DiscoveryClientCached.ServerResourcesForGroupVersion(gv) +func (dcs *DynamicClientSet) namespaced(gvk schema.GroupVersionKind) (bool, error) { + resourceList, err := dcs.DiscoveryClientCached.ServerResourcesForGroupVersion(gvk.GroupVersion().String()) if err != nil { - return false, fmt.Errorf("failed to find server resources for GV: %q - %v", gv, err) + return false, err } for _, resource := range resourceList.APIResources { diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 7656466a33..24f72cefcb 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -79,13 +79,12 @@ type kubeOpts struct { } type kubeProvider struct { - host *provider.HostClient - canceler *cancellationContext - name string - version string - providerPrefix string - opts kubeOpts - overrideNamespace string + host *provider.HostClient + canceler *cancellationContext + name string + version string + providerPrefix string + opts kubeOpts clientSet *clients.DynamicClientSet } @@ -139,10 +138,6 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ CurrentContext: vars["kubernetes:config:context"], } - if overrides.Context.Namespace != "" { - k.overrideNamespace = overrides.Context.Namespace - } - var kubeconfig clientcmd.ClientConfig if configJSON, ok := vars["kubernetes:config:kubeconfig"]; ok { config, err := clientcmd.Load([]byte(configJSON)) @@ -277,17 +272,6 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) ( return nil, err } - if k.overrideNamespace != "" { - namespacedKind, err := k.clientSet.NamespacedKind(gvk) - if err != nil { - return nil, err - } - - if namespacedKind { - newInputs.SetNamespace(k.overrideNamespace) - } - } - // HACK: Do not validate against OpenAPI spec if there is a computed value. The OpenAPI spec // does not know how to deal with the placeholder values for computed values. if !hasComputedValue(newInputs) { diff --git a/tests/integration/provider/provider_test.go b/tests/integration/provider/provider_test.go deleted file mode 100644 index 49b0477b63..0000000000 --- a/tests/integration/provider/provider_test.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2016-2019, Pulumi Corporation. -// -// 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 ints - -import ( - "os" - "testing" - - "github.com/pulumi/pulumi/pkg/tokens" - - "github.com/pulumi/pulumi-kubernetes/pkg/openapi" - "github.com/pulumi/pulumi-kubernetes/tests" - "github.com/pulumi/pulumi/pkg/resource" - "github.com/pulumi/pulumi/pkg/resource/deploy/providers" - "github.com/pulumi/pulumi/pkg/testing/integration" - "github.com/stretchr/testify/assert" -) - -func TestProvider(t *testing.T) { - kubectx := os.Getenv("KUBERNETES_CONTEXT") - - if kubectx == "" { - t.Skipf("Skipping test due to missing KUBERNETES_CONTEXT variable") - } - - integration.ProgramTest(t, &integration.ProgramTestOptions{ - Dir: "step1", - Dependencies: []string{"@pulumi/kubernetes"}, - Quick: true, - ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) { - assert.NotNil(t, stackInfo.Deployment) - assert.Equal(t, 7, len(stackInfo.Deployment.Resources)) - - tests.SortResourcesByURN(stackInfo) - - stackRes := stackInfo.Deployment.Resources[6] - assert.Equal(t, resource.RootStackType, stackRes.URN.Type()) - - k8sProvider := stackInfo.Deployment.Resources[5] - assert.True(t, providers.IsProviderType(k8sProvider.URN.Type())) - - defaultProvider := stackInfo.Deployment.Resources[4] - assert.True(t, providers.IsProviderType(defaultProvider.URN.Type())) - - // Assert the provider Namespace was created - providerNamespace := stackInfo.Deployment.Resources[0] - assert.Equal(t, tokens.Type("kubernetes:core/v1:Namespace"), providerNamespace.URN.Type()) - providerNsName, _ := openapi.Pluck(providerNamespace.Outputs, "metadata", "name") - - // Assert the other Namespace was created despite the provider override. - otherNamespace := stackInfo.Deployment.Resources[1] - assert.Equal(t, tokens.Type("kubernetes:core/v1:Namespace"), otherNamespace.URN.Type()) - nsName, _ := openapi.Pluck(otherNamespace.Outputs, "metadata", "name") - assert.NotEqual(t, nsName, providerNsName) - - // Assert the Pod was created in the provider namespace. - pod := stackInfo.Deployment.Resources[3] - assert.Equal(t, "nginx", string(pod.URN.Name())) - podNamespace, _ := openapi.Pluck(pod.Outputs, "metadata", "namespace") - assert.Equal(t, providerNamespace.ID.String(), podNamespace.(string)) - - // Assert the Pod was created in the provider namespace rather than the specified namespace. - namespacedPod := stackInfo.Deployment.Resources[2] - assert.Equal(t, "namespaced-nginx", string(namespacedPod.URN.Name())) - namespacedPodNamespace, _ := openapi.Pluck(namespacedPod.Outputs, "metadata", "namespace") - assert.Equal(t, providerNamespace.ID.String(), namespacedPodNamespace.(string)) - }, - }) -} diff --git a/tests/integration/provider/step1/Pulumi.yaml b/tests/integration/provider/step1/Pulumi.yaml deleted file mode 100644 index 4c858f295c..0000000000 --- a/tests/integration/provider/step1/Pulumi.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: provider -description: Tests first-class provider support. -runtime: nodejs diff --git a/tests/integration/provider/step1/index.ts b/tests/integration/provider/step1/index.ts deleted file mode 100644 index 74d33b7ee0..0000000000 --- a/tests/integration/provider/step1/index.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2016-2019, Pulumi Corporation. -// -// 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. - -import * as k8s from "@pulumi/kubernetes"; -import * as fs from "fs"; -import * as os from "os"; -import * as path from "path"; - -// Use the existing ~/.kube/config kubeconfig -const kubeconfig = fs.readFileSync(path.join(os.homedir(), ".kube", "config")).toString(); - -const ns = new k8s.core.v1.Namespace("ns"); - -// Create a new provider -const myk8s = new k8s.Provider("myk8s", { - kubeconfig: kubeconfig, - namespace: ns.metadata.name, -}); - -// Create a Pod using the custom provider. -// The namespace should be automatically set by the provider override. -new k8s.core.v1.Pod("nginx", { - spec: { - containers: [{ - image: "nginx:1.7.9", - name: "nginx", - ports: [{ containerPort: 80 }], - }], - }, -}, { provider: myk8s }); - -// Create a Pod using the custom provider with a specified namespace. -// The namespace should be overridden by the provider override. -new k8s.core.v1.Pod("namespaced-nginx", { - metadata: { namespace: ns.metadata.name }, - spec: { - containers: [{ - image: "nginx:1.7.9", - name: "nginx", - ports: [{ containerPort: 80 }], - }], - }, -}, { provider: myk8s }); - -// Create a Namespace using the custom provider -// The namespace should not be affected by the provider override since it is a non-namespaceable kind. -new k8s.core.v1.Namespace("other-ns", - {}, - { provider: myk8s }); diff --git a/tests/integration/provider/step1/package.json b/tests/integration/provider/step1/package.json deleted file mode 100644 index bebf7a4efa..0000000000 --- a/tests/integration/provider/step1/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "steps", - "version": "0.1.0", - "dependencies": { - "@pulumi/pulumi": "dev", - "@pulumi/random": "dev" - }, - "devDependencies": { - "typescript": "^3.0.0" - }, - "peerDependencies": { - "@pulumi/kubernetes": "latest" - } -} diff --git a/tests/integration/provider/step1/tsconfig.json b/tests/integration/provider/step1/tsconfig.json deleted file mode 100644 index 5dacccbd42..0000000000 --- a/tests/integration/provider/step1/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "compilerOptions": { - "outDir": "bin", - "target": "es6", - "module": "commonjs", - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "stripInternal": true, - "experimentalDecorators": true, - "pretty": true, - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "forceConsistentCasingInFileNames": true, - "strictNullChecks": true - }, - "files": [ - "index.ts" - ] -} -