Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Feb 5, 2019
1 parent f77579a commit f236702
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 44 deletions.
4 changes: 2 additions & 2 deletions pkg/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,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
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func (dcs *DynamicClientSet) gvkForKind(kind Kind) (*schema.GroupVersionKind, er
return nil, fmt.Errorf("failed to find gvk for Kind: %q", kind)
}

func (dcs *DynamicClientSet) NamespacedKind(gvk schema.GroupVersionKind) (bool, error) {
func (dcs *DynamicClientSet) namespaced(gvk schema.GroupVersionKind) (bool, error) {
resourceList, err := dcs.getServerResourcesForGV(gvk.GroupVersion())
if err != nil {
return false, err
Expand Down
41 changes: 1 addition & 40 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (
assignNameIfAutonamable(newInputs, urn.Name())
}

newInputs, err = ensureCanonicalNamespace(newInputs, k.clientSet)
if err != nil {
return nil, err
}

gvk, err := k.gvkFromURN(urn)
if err != nil {
return nil, err
Expand Down Expand Up @@ -419,11 +414,6 @@ func (k *kubeProvider) Create(
}
newInputs := propMapToUnstructured(newResInputs)

newInputs, err = ensureCanonicalNamespace(newInputs, k.clientSet)
if err != nil {
return nil, err
}

config := await.CreateConfig{
ProviderConfig: await.ProviderConfig{
Context: k.canceler.context,
Expand Down Expand Up @@ -509,16 +499,7 @@ func (k *kubeProvider) Read(ctx context.Context, req *pulumirpc.ReadRequest) (*p
oldInputs.SetGroupVersionKind(newInputs.GroupVersionKind())
}

namespacedKind, err := k.clientSet.NamespacedKind(oldInputs.GroupVersionKind())
if err != nil {
return nil, err
}

ns, name := ParseFqName(req.GetId())
ns = canonicalNamespace(ns)
if namespacedKind && oldInputs.GetNamespace() == "" {
oldInputs.SetNamespace(ns)
}
_, name := ParseFqName(req.GetId())
if oldInputs.GetName() == "" {
oldInputs.SetName(name)
}
Expand Down Expand Up @@ -671,11 +652,6 @@ func (k *kubeProvider) Update(
}
newInputs := propMapToUnstructured(newResInputs)

newInputs, err = ensureCanonicalNamespace(newInputs, k.clientSet)
if err != nil {
return nil, err
}

config := await.UpdateConfig{
ProviderConfig: await.ProviderConfig{
Context: k.canceler.context,
Expand Down Expand Up @@ -891,18 +867,3 @@ func canonicalNamespace(ns string) string {
}
return ns
}

// ensureCanonicalNamespace returns an object with a canonical namespace set if the object Kind
// is namespaced. Otherwise, no namespace is set on the returned object.
func ensureCanonicalNamespace(obj *unstructured.Unstructured, dcs *clients.DynamicClientSet,
) (*unstructured.Unstructured, error) {
namespacedKind, err := dcs.NamespacedKind(obj.GroupVersionKind())
if err != nil {
return nil, err
}
if namespacedKind {
obj.SetNamespace(canonicalNamespace(obj.GetNamespace()))
}

return obj, nil
}
6 changes: 4 additions & 2 deletions tests/integration/istio/step1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"dependencies": {
"@pulumi/pulumi": "^0.15.0",
"@pulumi/random": "^0.3.0",
"@pulumi/gcp": "latest",
"@pulumi/kubernetes": "^0.17.4"
"@pulumi/gcp": "latest"
},
"peerDependencies": {
"@pulumi/kubernetes": "latest"
}
}

0 comments on commit f236702

Please sign in to comment.