Skip to content

Commit

Permalink
chore: Clean up devfile registry deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha committed Aug 7, 2024
1 parent 9cb33f9 commit 082dde9
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/v2/checluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ type CheClusterStatus struct {
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="ChePhase"
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:text"
ChePhase CheClusterPhase `json:"chePhase,omitempty"`
// The public URL of the internal devfile registry.
// Deprecated the public URL of the internal devfile registry.
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=status
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Devfile registry URL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che.v7.90.0-877.next
name: eclipse-che.v7.90.0-878.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -225,7 +225,7 @@ spec:
path: cheVersion
x-descriptors:
- urn:alm:descriptor:text
- description: The public URL of the internal devfile registry.
- description: Deprecated the public URL of the internal devfile registry.
displayName: Devfile registry URL
path: devfileRegistryURL
x-descriptors:
Expand Down Expand Up @@ -916,6 +916,8 @@ spec:
{"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]'
- name: CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL
value: https://open-vsx.org
- name: CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES
value: '[{"url": "https://registry.devfile.io"}]'
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES
value: "false"
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_CONTAINERSECURITYCONTEXT
Expand Down Expand Up @@ -1033,7 +1035,7 @@ spec:
minKubeVersion: 1.19.0
provider:
name: Eclipse Foundation
version: 7.90.0-877.next
version: 7.90.0-878.next
webhookdefinitions:
- admissionReviewVersions:
- v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8338,7 +8338,7 @@ spec:
description: Currently installed Che version.
type: string
devfileRegistryURL:
description: The public URL of the internal devfile registry.
description: Deprecated the public URL of the internal devfile registry.
type: string
gatewayPhase:
description: Specifies the current phase of the gateway deployment.
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/org.eclipse.che_checlusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8285,7 +8285,7 @@ spec:
description: Currently installed Che version.
type: string
devfileRegistryURL:
description: The public URL of the internal devfile registry.
description: Deprecated the public URL of the internal devfile registry.
type: string
gatewayPhase:
description: Specifies the current phase of the gateway deployment.
Expand Down
2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ spec:
value: '[{"name": "universal-developer-image", "container": {"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]'
- name: CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL
value: https://open-vsx.org
- name: CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES
value: '[{"url": "https://registry.devfile.io"}]'
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES
value: 'false'
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_CONTAINERSECURITYCONTEXT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ spec:
path: cheVersion
x-descriptors:
- urn:alm:descriptor:text
- description: The public URL of the internal devfile registry.
- description: Deprecated the public URL of the internal devfile registry.
displayName: Devfile registry URL
path: devfileRegistryURL
x-descriptors:
Expand Down
4 changes: 3 additions & 1 deletion deploy/deployment/kubernetes/combined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8306,7 +8306,7 @@ spec:
description: Currently installed Che version.
type: string
devfileRegistryURL:
description: The public URL of the internal devfile registry.
description: Deprecated the public URL of the internal devfile registry.
type: string
gatewayPhase:
description: Specifies the current phase of the gateway deployment.
Expand Down Expand Up @@ -8867,6 +8867,8 @@ spec:
value: '[{"name": "universal-developer-image", "container": {"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]'
- name: CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL
value: https://open-vsx.org
- name: CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES
value: '[{"url": "https://registry.devfile.io"}]'
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES
value: "false"
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_CONTAINERSECURITYCONTEXT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ spec:
value: '[{"name": "universal-developer-image", "container": {"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]'
- name: CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL
value: https://open-vsx.org
- name: CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES
value: '[{"url": "https://registry.devfile.io"}]'
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES
value: "false"
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_CONTAINERSECURITYCONTEXT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8301,7 +8301,7 @@ spec:
description: Currently installed Che version.
type: string
devfileRegistryURL:
description: The public URL of the internal devfile registry.
description: Deprecated the public URL of the internal devfile registry.
type: string
gatewayPhase:
description: Specifies the current phase of the gateway deployment.
Expand Down
4 changes: 3 additions & 1 deletion deploy/deployment/openshift/combined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8306,7 +8306,7 @@ spec:
description: Currently installed Che version.
type: string
devfileRegistryURL:
description: The public URL of the internal devfile registry.
description: Deprecated the public URL of the internal devfile registry.
type: string
gatewayPhase:
description: Specifies the current phase of the gateway deployment.
Expand Down Expand Up @@ -8869,6 +8869,8 @@ spec:
value: '[{"name": "universal-developer-image", "container": {"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]'
- name: CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL
value: https://open-vsx.org
- name: CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES
value: '[{"url": "https://registry.devfile.io"}]'
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES
value: "false"
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_CONTAINERSECURITYCONTEXT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ spec:
value: '[{"name": "universal-developer-image", "container": {"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]'
- name: CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL
value: https://open-vsx.org
- name: CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES
value: '[{"url": "https://registry.devfile.io"}]'
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES
value: "false"
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_CONTAINERSECURITYCONTEXT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8301,7 +8301,7 @@ spec:
description: Currently installed Che version.
type: string
devfileRegistryURL:
description: The public URL of the internal devfile registry.
description: Deprecated the public URL of the internal devfile registry.
type: string
gatewayPhase:
description: Specifies the current phase of the gateway deployment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8301,7 +8301,7 @@ spec:
description: Currently installed Che version.
type: string
devfileRegistryURL:
description: The public URL of the internal devfile registry.
description: Deprecated the public URL of the internal devfile registry.
type: string
gatewayPhase:
description: Specifies the current phase of the gateway deployment.
Expand Down
2 changes: 2 additions & 0 deletions helmcharts/next/templates/che-operator.Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ spec:
value: '[{"name": "universal-developer-image", "container": {"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]'
- name: CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL
value: https://open-vsx.org
- name: CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES
value: '[{"url": "https://registry.devfile.io"}]'
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES
value: "false"
- name: CHE_DEFAULT_SPEC_DEVENVIRONMENTS_CONTAINERSECURITYCONTEXT
Expand Down
10 changes: 10 additions & 0 deletions pkg/common/operator-defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
defaultDevEnvironmentsContainerSecurityContext string
defaultPluginRegistryOpenVSXURL string
defaultDashboardHeaderMessageText string
defaultDevfileRegistryExternalDevfileRegistries string

initialized = false
)
Expand Down Expand Up @@ -82,6 +83,7 @@ func Initialize() {
defaultDevEnvironmentsDefaultEditor = os.Getenv("CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DEFAULTEDITOR")
defaultPluginRegistryOpenVSXURL = os.Getenv("CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL")
defaultDashboardHeaderMessageText = os.Getenv("CHE_DEFAULT_SPEC_COMPONENTS_DASHBOARD_HEADERMESSAGE_TEXT")
defaultDevfileRegistryExternalDevfileRegistries = os.Getenv("CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES")

defaultCheServerImage = ensureEnv(util.GetArchitectureDependentEnvName("RELATED_IMAGE_che_server"))
defaultDashboardImage = ensureEnv(util.GetArchitectureDependentEnvName("RELATED_IMAGE_dashboard"))
Expand Down Expand Up @@ -222,6 +224,14 @@ func GetConsoleLinkImage() string {
return defaultsConsoleLinkImage
}

func GetDevfileRegistryExternalDevfileRegistries() string {
if !initialized {
logrus.Fatalf("Operator defaults are not initialized.")
}

return defaultDevfileRegistryExternalDevfileRegistries
}

func GetPluginRegistryOpenVSXURL() string {
if !initialized {
logrus.Fatalf("Operator defaults are not initialized.")
Expand Down
8 changes: 8 additions & 0 deletions pkg/deploy/dashboard/dashboard_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
Name: "CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DEFAULTCOMPONENTS",
Value: defaults.GetDevEnvironmentsDefaultComponents(),
},
{
Name: "CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES",
Value: defaults.GetDevfileRegistryExternalDevfileRegistries(),
},
{
Name: "CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL",
Value: defaults.GetPluginRegistryOpenVSXURL(),
Expand Down Expand Up @@ -262,6 +266,10 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
Name: "CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL",
Value: "http://plugin-registry.eclipse-che.svc:8080/v3",
},
{
Name: "CHE_DEFAULT_SPEC_COMPONENTS_DEVFILEREGISTRY_EXTERNAL_DEVFILE_REGISTRIES",
Value: defaults.GetDevfileRegistryExternalDevfileRegistries(),
},
{
Name: "OPENSHIFT_CONSOLE_URL",
Value: "https://console-openshift-console.apps.my-host/",
Expand Down
41 changes: 41 additions & 0 deletions pkg/deploy/devfileregistry/devfileregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
package devfileregistry

import (
"context"
"encoding/json"

v2 "github.com/eclipse-che/che-operator/api/v2"
defaults "github.com/eclipse-che/che-operator/pkg/common/operator-defaults"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/eclipse-che/che-operator/pkg/common/chetypes"
"github.com/eclipse-che/che-operator/pkg/common/constants"
Expand All @@ -23,6 +29,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

var (
logger = ctrl.Log.WithName("devfile-registry")
)

type DevfileRegistryReconciler struct {
deploy.Reconcilable
}
Expand All @@ -38,6 +48,37 @@ func (d *DevfileRegistryReconciler) Reconcile(ctx *chetypes.DeployContext) (reco
_, _ = deploy.DeleteNamespacedObject(ctx, constants.DevfileRegistryName, &appsv1.Deployment{})

if ctx.CheCluster.Status.DevfileRegistryURL != "" {
var externalDevfileRegistries []v2.ExternalDevfileRegistry
if err := json.Unmarshal([]byte(defaults.GetDevfileRegistryExternalDevfileRegistries()), &externalDevfileRegistries); err == nil {

// Add default external devfile registries to the CheCluster CR
for _, newRegistry := range externalDevfileRegistries {
newRegistryAlreadyExists := false
for _, existedRegistry := range ctx.CheCluster.Spec.Components.DevfileRegistry.ExternalDevfileRegistries {
if existedRegistry.Url == newRegistry.Url {
newRegistryAlreadyExists = true
break
}
}

if !newRegistryAlreadyExists {
logger.Info("Adding external devfile registry to the CheCluster CR", "Url", newRegistry.Url)
ctx.CheCluster.Spec.Components.DevfileRegistry.ExternalDevfileRegistries =
append(ctx.CheCluster.Spec.Components.DevfileRegistry.ExternalDevfileRegistries, newRegistry)
}
}

if err := ctx.ClusterAPI.Client.Update(context.TODO(), ctx.CheCluster); err != nil {
return reconcile.Result{}, false, err
}
} else {
logger.Error(
err, "Failed to unmarshal environment variable",
"key", "CHE_OPERATOR_DEFAULTS_DEVFILE_REGISTRY_EXTERNAL_DEVFILE_REGISTRIES",
"value", defaults.GetDevfileRegistryExternalDevfileRegistries(),
)
}

ctx.CheCluster.Status.DevfileRegistryURL = ""
_ = deploy.UpdateCheCRStatus(ctx, "DevfileRegistryURL", "")
}
Expand Down
Loading

0 comments on commit 082dde9

Please sign in to comment.