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

Don't fail workspaces that use Kubernetes/OpenShift components with URIs #1104

Merged
merged 2 commits into from
May 23, 2023
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
15 changes: 13 additions & 2 deletions pkg/library/kubernetes/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package kubernetes
import (
"fmt"
"reflect"
"strings"

"github.com/devfile/devworkspace-operator/pkg/common"
"github.com/devfile/devworkspace-operator/pkg/constants"
Expand All @@ -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 {
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ input:
targetPort: 8081

output:
errRegexp: "components that define a URI are unsupported"
errRegexp: "Ignored components that use unsupported features"
18 changes: 14 additions & 4 deletions pkg/library/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions webhook/workspace/handler/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A future improvement could be to return a webhook warning (so that the dashboard could display it) but for now, I don't think this is necessary.

continue
}
if component.Inlined == "" {
return fmt.Errorf("kubernetes component does not define inlined content")
Expand All @@ -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")
Expand Down