Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort plan with FATAL_ERROR if an unknown custom resource deployed #1648

Merged
merged 2 commits into from
Aug 25, 2020
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
10 changes: 10 additions & 0 deletions pkg/engine/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"reflect"

"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/client-go/discovery"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -61,6 +62,15 @@ func IsHealthy(obj runtime.Object) error {

objUnstructured := &unstructured.Unstructured{Object: unstructMap}
switch obj := obj.(type) {
case *v1beta1.CustomResourceDefinition:
for _, c := range obj.Status.Conditions {
if c.Type == v1beta1.Established && c.Status == v1beta1.ConditionTrue {
log.Printf("CRD %s is now healthy", obj.Name)
return nil
}
}
msg := fmt.Sprintf("CRD %s is not healthy ( Conditions: %v )", obj.Name, obj.Status.Conditions)
return errors.New(msg)
case *appsv1.StatefulSet:
statusViewer := &polymorphichelpers.StatefulSetStatusViewer{}
msg, done, err := statusViewer.Status(objUnstructured, 0)
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/renderer/enhancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (de *DefaultEnhancer) Apply(sourceObjs []runtime.Object, metadata Metadata)

isNamespaced, err := resource.IsNamespacedObject(obj, de.Discovery)
if err != nil {
return nil, fmt.Errorf("failed to determine if object %s is namespaced: %v", obj.GetObjectKind(), err)
return nil, fmt.Errorf("%wfailed to determine if object %s is namespaced: %v", engine.ErrFatalExecution, obj.GetObjectKind(), err)
}

// Note: Cross-namespace owner references are disallowed by design. This means:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: kudo.dev/v1beta1
kind: Instance
metadata:
name: crd-instance
name: op-with-crd
spec:
operatorVersion:
name: crd-operator-0.1.0
name: op-with-crd-0.1.0
status:
planStatus:
deploy:
status: COMPLETE
status: FATAL_ERROR
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: kudo.dev/v1beta1
kind: TestStep
commands:
- command: kubectl kudo install --instance crd-instance ./operator
- command: kubectl kudo install --instance op-with-crd ./op-with-crd
namespaced: true
25 changes: 25 additions & 0 deletions test/integration/invalid-crd-install/op-with-crd/operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: kudo.dev/v1beta1
name: "op-with-crd"
operatorVersion: "0.1.0"
appVersion: "1.7.9"
kubernetesVersion: 1.13.0
maintainers:
- name: Your name
email: <[email protected]>
url: https://kudo.dev
tasks:
- name: app
kind: Apply
spec:
resources:
- invalid-crd.yaml
plans:
deploy:
strategy: serial
phases:
- name: main
strategy: parallel
steps:
- name: everything
tasks:
- app
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apiVersion: kudo.dev/v1beta1
parameters:
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: somecrd.invalid/v1
kind: InvalidCrdType
metadata:
name: {{ .Name }}-resource
namespace: {{ .Namespace }}
spec:
this:
does-not: "matter"
there-is-no: "such-crd"
14 changes: 13 additions & 1 deletion test/integration/operator-with-custom-crd/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: servicemonitors.monitoring.coreos.com
name: servicemonitors.monitoring.coreos.com
---
apiVersion: kudo.dev/v1beta1
kind: Instance
metadata:
name: crd-instance
spec:
operatorVersion:
name: crd-operator-0.1.0
status:
planStatus:
deploy:
status: COMPLETE
Loading