Skip to content

Commit

Permalink
Return an error if a resource with a given GVK is missing in the API …
Browse files Browse the repository at this point in the history
…resource list
  • Loading branch information
zen-dog committed Jan 27, 2020
1 parent 6ecf51b commit 5d34c34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 5 additions & 1 deletion pkg/engine/task/task_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ func isNamespaced(r runtime.Object) (bool, error) {
}

gvk := r.GetObjectKind().GroupVersionKind()
return namespaced[gvk], nil
res, ok := namespaced[gvk]
if !ok {
return false, fmt.Errorf("a resource with GVK %v seems to be missing in API resource list", gvk)
}
return res, nil
}

// patch calls update method on kubernetes client to make sure the current resource reflects what is on server
Expand Down
10 changes: 0 additions & 10 deletions pkg/engine/task/task_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -190,12 +189,3 @@ type errorEnhancer struct{}
func (k *errorEnhancer) Apply(templates map[string]string, metadata renderer.Metadata) ([]runtime.Object, error) {
return nil, errors.New("always error")
}

func Test_namespacedGVKResources(t *testing.T) {
got, err := namespacedGVKResources()
assert.NoError(t, err)

// just a small sanity check
assert.True(t, got[schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"}])
assert.False(t, got[schema.GroupVersionKind{Group: "apiextensions.k8s.io", Version: "v1", Kind: "CustomResourceDefinition"}])
}

0 comments on commit 5d34c34

Please sign in to comment.