Skip to content

Commit

Permalink
Set CHE_DEVFILE_REGISTRY_URL to allow airgap operation (#102)
Browse files Browse the repository at this point in the history
* Set CHE_DEVFILE_HTTPS_ENDPOINT and react to changes on it
* Change HTTPS_ENDPOINT to REGISTRY_URL
* Only set the devfile registry URL to the autogenerated one when we are not using an external devfile registry

Signed-off-by: Tom George <tg82490@gmail.com>
  • Loading branch information
tomgeorge authored and davidfestal committed Oct 28, 2019
1 parent 4b0b485 commit 0e99d74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 10 additions & 10 deletions pkg/controller/che/che_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,23 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e
}

devfileRegistryURL := instance.Spec.Server.DevfileRegistryUrl

// Create devfile registry resources unless an external registry is used
externalDevfileRegistry := instance.Spec.Server.ExternalDevfileRegistry
if !externalDevfileRegistry {
guessedDevfileRegistryURL, err := addRegistryRoute("devfile")
if err != nil {
return reconcile.Result{}, err
}
if devfileRegistryURL == "" {
devfileRegistryURL = guessedDevfileRegistryURL
}
if instance.IsAirGapMode() {
devFileRegistryConfigMap := &corev1.ConfigMap{}
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 +860,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 +875,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

0 comments on commit 0e99d74

Please sign in to comment.