Skip to content

Commit

Permalink
operator: add Registry to ManagedOSVersionChannels Spec (#831)
Browse files Browse the repository at this point in the history
The new Registry field allows to prepend a common registry to the
image URLs of the embedded ManagedOSVersion resources.

Fixes #549

Signed-off-by: Francesco Giudici <[email protected]>
  • Loading branch information
fgiudici authored Sep 3, 2024
1 parent 122109f commit 198628f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .obs/chartfile/crds/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,11 @@ spec:
type: boolean
options:
x-kubernetes-preserve-unknown-fields: true
registry:
description: |-
Registry defines a common registry to be prepended to the 'uri' or 'upgradeImage'
of each extracted ManagedOSVersion resource.
type: string
syncInterval:
default: 1h
type: string
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/managedosversionchannel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type ManagedOSVersionChannelSpec struct {
// +optional
// +kubebuilder:default:=true
Enabled bool `json:"enabled"`
// Registry defines a common registry to be prepended to the 'uri' or 'upgradeImage'
// of each extracted ManagedOSVersion resource.
// +optional
Registry string `json:"registry,omitempty"`
// +kubebuilder:validation:Schemaless
// +kubebuilder:validation:XPreserveUnknownFields
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ spec:
type: boolean
options:
x-kubernetes-preserve-unknown-fields: true
registry:
description: |-
Registry defines a common registry to be prepended to the 'uri' or 'upgradeImage'
of each extracted ManagedOSVersion resource.
type: string
syncInterval:
default: 1h
type: string
Expand Down
25 changes: 25 additions & 0 deletions controllers/managedosversionchannel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
errorutils "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/workqueue"
Expand Down Expand Up @@ -357,6 +359,29 @@ func (r *ManagedOSVersionChannelReconciler) createManagedOSVersions(ctx context.
vcpy.Spec.UpgradeContainer = ch.Spec.UpgradeContainer
}

if len(ch.Spec.Registry) > 0 {
registry := ch.Spec.Registry
urlField := ""
switch {
case vcpy.IsContainerImage():
urlField = "upgradeImage"
case vcpy.IsISOImage():
urlField = "uri"
default:
err := fmt.Errorf("unexpected ManagedOSVersion type %s", vcpy.Spec.Type)
logger.Error(err, "failed to concatenate managedosversion with registry", "registry", ch.Spec.Registry)
return err
}

val := strings.Trim(string(vcpy.Spec.Metadata[urlField].Raw), "\"")
if !strings.HasSuffix(ch.Spec.Registry, "/") && !strings.HasPrefix(val, "/") {
registry += "/"
}
vcpy.Spec.Metadata[urlField] = runtime.RawExtension{
Raw: []byte(fmt.Sprintf("\"%s%s\"", registry, val)),
}
}

if cv, ok := curVersions[v.Name]; ok {
patchBase := client.MergeFrom(cv.DeepCopy())
cv.Spec = vcpy.Spec
Expand Down

0 comments on commit 198628f

Please sign in to comment.