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

Set CHE_DEVFILE_REGISTRY_URL to allow airgap operation #102

Merged
merged 3 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 11 additions & 10 deletions pkg/controller/che/che_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,15 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}

devfileRegistryURL := instance.Spec.Server.DevfileRegistryUrl

guessedDevfileRegistryURL, err := addRegistryRoute("devfile")
if err != nil {
return reconcile.Result{}, err
}
if devfileRegistryURL == "" {
devfileRegistryURL = guessedDevfileRegistryURL
}

// Create devfile registry resources unless an external registry is used
externalDevfileRegistry := instance.Spec.Server.ExternalDevfileRegistry
if !externalDevfileRegistry {
Expand All @@ -834,7 +843,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
err = r.client.Get(context.TODO(), types.NamespacedName{Name: "devfile-registry", Namespace: instance.Namespace}, devFileRegistryConfigMap)
if err != nil {
if errors.IsNotFound(err) {
devFileRegistryConfigMap = deploy.CreateDevfileRegistryConfigMap(instance)
devFileRegistryConfigMap = deploy.CreateDevfileRegistryConfigMap(instance, devfileRegistryURL)
err = controllerutil.SetControllerReference(instance, devFileRegistryConfigMap, r.scheme)
if err != nil {
logrus.Errorf("An error occurred: %v", err)
Expand All @@ -852,7 +861,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
return reconcile.Result{}, err
}
} else {
devFileRegistryConfigMap = deploy.CreateDevfileRegistryConfigMap(instance)
devFileRegistryConfigMap = deploy.CreateDevfileRegistryConfigMap(instance, devfileRegistryURL)
err = controllerutil.SetControllerReference(instance, devFileRegistryConfigMap, r.scheme)
if err != nil {
logrus.Errorf("An error occurred: %v", err)
Expand All @@ -867,14 +876,6 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}
}

guessedDevfileRegistryURL, err := addRegistryRoute("devfile")
if err != nil {
return reconcile.Result{}, err
}
if devfileRegistryURL == "" {
devfileRegistryURL = guessedDevfileRegistryURL
}

devfileRegistryImage := util.GetValue(instance.Spec.Server.DevfileRegistryImage, deploy.DefaultDevfileRegistryImage(instance, cheFlavor))
result, err := addRegistryDeployment(
"devfile",
Expand Down
8 changes: 5 additions & 3 deletions pkg/deploy/registry_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
type DevFileRegistryConfigMap struct {
CheDevfileImagesRegistryURL string `json:"CHE_DEVFILE_IMAGES_REGISTRY_URL"`
CheDevfileImagesRegistryOrganization string `json:"CHE_DEVFILE_IMAGES_REGISTRY_ORGANIZATION"`
CheDevfileRegistryURL string `json:"CHE_DEVFILE_REGISTRY_URL"`
}

type PluginRegistryConfigMap struct {
CheSidecarContainersRegistryURL string `json:"CHE_SIDECAR_CONTAINERS_REGISTRY_URL"`
CheSidecarContainersRegistryOrganization string `json:"CHE_SIDECAR_CONTAINERS_REGISTRY_ORGANIZATION"`
}

func CreateDevfileRegistryConfigMap(cr *orgv1.CheCluster) *corev1.ConfigMap {
func CreateDevfileRegistryConfigMap(cr *orgv1.CheCluster, endpoint string) *corev1.ConfigMap {
labels := GetLabels(cr, util.GetValue(cr.Spec.Server.CheFlavor, DefaultCheFlavor))
return &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Expand All @@ -32,7 +33,7 @@ func CreateDevfileRegistryConfigMap(cr *orgv1.CheCluster) *corev1.ConfigMap {
Namespace: cr.Namespace,
Labels: labels,
},
Data: GetDevfileRegistryConfigMapData(cr),
Data: GetDevfileRegistryConfigMapData(cr, endpoint),
}
}

Expand All @@ -53,11 +54,12 @@ func CreatePluginRegistryConfigMap(cr *orgv1.CheCluster) *corev1.ConfigMap {
}
}

func GetDevfileRegistryConfigMapData(cr *orgv1.CheCluster) map[string]string {
func GetDevfileRegistryConfigMapData(cr *orgv1.CheCluster, endpoint string) map[string]string {
devfileRegistryEnv := make(map[string]string)
data := &DevFileRegistryConfigMap{
CheDevfileImagesRegistryURL: cr.Spec.Server.AirGapContainerRegistryHostname,
CheDevfileImagesRegistryOrganization: cr.Spec.Server.AirGapContainerRegistryOrganization,
CheDevfileRegistryURL: endpoint,
}

out, err := json.Marshal(data)
Expand Down