diff --git a/pkg/library/kubernetes/provision.go b/pkg/library/kubernetes/provision.go index 5e6e1bdcd..b8019443c 100644 --- a/pkg/library/kubernetes/provision.go +++ b/pkg/library/kubernetes/provision.go @@ -16,6 +16,7 @@ package kubernetes import ( "fmt" "reflect" + "strings" "github.com/devfile/devworkspace-operator/pkg/common" "github.com/devfile/devworkspace-operator/pkg/constants" @@ -32,13 +33,18 @@ import ( // has the correct permissions to create/update/delete these objects and instead assumes the // workspace owner has all applicable RBAC permissions. // Only Kubernetes/OpenShift components that are inlined are supported; components that define -// a URI will cause a FailError to be returned +// a URI will cause a WarningError to be returned func HandleKubernetesComponents(workspace *common.DevWorkspaceWithConfig, api sync.ClusterAPI) error { - kubeComponents, err := filterForKubeLikeComponents(workspace.Spec.Template.Components) + kubeComponents, warnings, err := filterForKubeLikeComponents(workspace.Spec.Template.Components) if err != nil { return err } if len(kubeComponents) == 0 { + if len(warnings) > 0 { + return &dwerrors.WarningError{ + Message: fmt.Sprintf("Ignored components that use unsupported features: %s", strings.Join(warnings, ", ")), + } + } return nil } for _, component := range kubeComponents { @@ -64,6 +70,11 @@ func HandleKubernetesComponents(workspace *common.DevWorkspaceWithConfig, api sy return dwerrors.WrapSyncError(syncErr) } } + if len(warnings) > 0 { + return &dwerrors.WarningError{ + Message: fmt.Sprintf("Ignored components that use unsupported features: %s", strings.Join(warnings, ", ")), + } + } return nil } diff --git a/pkg/library/kubernetes/testdata/provision_tests/error-if-object-not-inlined.yaml b/pkg/library/kubernetes/testdata/provision_tests/error-if-object-not-inlined.yaml index 57ece164b..c5cbdd8cd 100644 --- a/pkg/library/kubernetes/testdata/provision_tests/error-if-object-not-inlined.yaml +++ b/pkg/library/kubernetes/testdata/provision_tests/error-if-object-not-inlined.yaml @@ -25,4 +25,4 @@ input: targetPort: 8081 output: - errRegexp: "components that define a URI are unsupported" + errRegexp: "Ignored components that use unsupported features" diff --git a/pkg/library/kubernetes/util.go b/pkg/library/kubernetes/util.go index a3f73ef11..b96da0c62 100644 --- a/pkg/library/kubernetes/util.go +++ b/pkg/library/kubernetes/util.go @@ -18,7 +18,6 @@ import ( dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" "github.com/devfile/devworkspace-operator/pkg/common" - "github.com/devfile/devworkspace-operator/pkg/dwerrors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -31,24 +30,35 @@ func HasKubelikeComponent(workspace *common.DevWorkspaceWithConfig) bool { return false } -func filterForKubeLikeComponents(components []dw.Component) ([]dw.Component, error) { +func filterForKubeLikeComponents(components []dw.Component) (kubeComponents []dw.Component, warnings []string, err error) { var k8sLikeComponents []dw.Component for _, component := range components { k8sLikeComponent, err := getK8sLikeComponent(component) if err != nil { + // Not a kube component (e.g. container, image, etc.) continue } + + if !k8sLikeComponent.GetDeployByDefault() { + // Not handled by operator + continue + } + if k8sLikeComponent.Uri != "" { - return nil, &dwerrors.FailError{Message: fmt.Sprintf("kubernetes/openshift components that define a URI are unsupported (component %s)", component.Name)} + // Not currently supported; return a warning and ignore it but do not fail startup + warnings = append(warnings, fmt.Sprintf("component %s defines a Kubernetes/OpenShift component via URI", component.Name)) + continue } + if k8sLikeComponent.Inlined == "" { continue } + if k8sLikeComponent.GetDeployByDefault() { k8sLikeComponents = append(k8sLikeComponents, component) } } - return k8sLikeComponents, nil + return k8sLikeComponents, warnings, nil } // getK8sLikeComponent returns the K8sLikeComponent from a DevWorkspace component, diff --git a/webhook/workspace/handler/kubernetes.go b/webhook/workspace/handler/kubernetes.go index 9c397af90..5233e7ffa 100644 --- a/webhook/workspace/handler/kubernetes.go +++ b/webhook/workspace/handler/kubernetes.go @@ -42,7 +42,8 @@ func (h *WebhookHandler) validateKubernetesObjectPermissionsOnCreate(ctx context continue } if component.Uri != "" { - return fmt.Errorf("kubenetes components specified via URI are unsupported") + // We're going to ignore URI components for now + continue } if component.Inlined == "" { return fmt.Errorf("kubernetes component does not define inlined content") @@ -66,7 +67,8 @@ func (h *WebhookHandler) validateKubernetesObjectPermissionsOnUpdate(ctx context } if newComponent.Uri != "" { - return fmt.Errorf("kubenetes components specified via URI are unsupported") + // We're going to ignore URI components for now + continue } if newComponent.Inlined == "" { return fmt.Errorf("kubernetes component does not define inlined content")