Skip to content

Commit

Permalink
Backport to v1.6.x (#796)
Browse files Browse the repository at this point in the history
* Add development channel for OBS builds

This commit adds a development channel reference to builds
done in OBS (under or branched from isv:Rancher:Elemental)

Signed-off-by: David Cassany <[email protected]>
(cherry picked from commit 6ee9211)

* Check crds chart is aligned with the main operator chart version

Signed-off-by: David Cassany <[email protected]>
(cherry picked from commit 0f59b14)

* Update channels (#781)

* Update channels
* Adding a downgrade/upgrade charts e2e test
* Only fetch logs for running containers
* Do not fail fast in e2e matrix

Signed-off-by: David Cassany <[email protected]>
(cherry picked from commit d7a712d)

* [Airgap] fix unstable channel extraction

Signed-off-by: Loic Devulder <[email protected]>
(cherry picked from commit b866419)

* Add Micro 6.0 baremetal as the default channel

Signed-off-by: David Cassany <[email protected]>

---------

Signed-off-by: David Cassany <[email protected]>
Co-authored-by: Loic Devulder <[email protected]>
  • Loading branch information
davidcassany and ldevulder authored Aug 5, 2024
1 parent 181714c commit 239f7fd
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ jobs:
overwrite: true

e2e-tests:
continue-on-error: true
strategy:
fail-fast: false
matrix:
kubernetes: [ "v1.23.17", "v1.24.15", "v1.25.11", "v1.26.6" ]
replicas: ["1"]
Expand Down
36 changes: 36 additions & 0 deletions .obs/chartfile/crds/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: machineinventories.elemental.cattle.io
spec:
Expand Down Expand Up @@ -198,10 +202,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: machineinventoryselectors.elemental.cattle.io
spec:
Expand Down Expand Up @@ -405,10 +413,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: machineinventoryselectortemplates.elemental.cattle.io
spec:
Expand Down Expand Up @@ -640,10 +652,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: machineregistrations.elemental.cattle.io
spec:
Expand Down Expand Up @@ -964,10 +980,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: managedosimages.elemental.cattle.io
spec:
Expand Down Expand Up @@ -2502,10 +2522,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: managedosversionchannels.elemental.cattle.io
spec:
Expand Down Expand Up @@ -2998,10 +3022,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: managedosversions.elemental.cattle.io
spec:
Expand Down Expand Up @@ -3404,10 +3432,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: metadata.elemental.cattle.io
spec:
Expand Down Expand Up @@ -3461,10 +3493,14 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/part-of: Elemental Operator
app.kubernetes.io/version: '{{ .Chart.Version }}'
controller-gen.kubebuilder.io/version: v0.14.0
labels:
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
release-name: '{{ .Release.Name }}'
name: seedimages.elemental.cattle.io
spec:
Expand Down
13 changes: 13 additions & 0 deletions .obs/chartfile/operator/templates/channel-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Unstable channel for testing isv:Rancher:Elemental OBS projects
# it is only rendered if the registryUrl value includes a known OBS project reference
{{ if and (hasPrefix "registry.opensuse.org" .Values.registryUrl) (contains "isv/rancher/elemental" .Values.registryUrl) }}
apiVersion: elemental.cattle.io/v1beta1
kind: ManagedOSVersionChannel
metadata:
name: unstable-testing-channel
namespace: fleet-default
spec:
options:
image: {{ .Values.registryUrl }}/rancher/elemental-unstable-channel:latest
type: custom
{{ end }}
11 changes: 0 additions & 11 deletions .obs/chartfile/operator/templates/channel.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions .obs/chartfile/operator/templates/channels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ $defChannelName := "" }}
{{ if and .Values.channel .Values.channel.image .Values.channel.tag .Values.channel.name }}
{{ $defChannelName := .Values.channel.name }}
apiVersion: elemental.cattle.io/v1beta1
kind: ManagedOSVersionChannel
metadata:
name: {{ .Values.channel.name }}
namespace: fleet-default
spec:
options:
image: {{ .Values.channel.image }}:{{ .Values.channel.tag }}
type: custom
{{ end }}

# Keep pre-existing channels managed by Helm if they do not match with the current default
# this way if an upgrade introduces a new channel any pre-existing channel managed by Helm is not deleted
{{ range $index, $channel := (lookup "elemental.cattle.io/v1beta1" "ManagedOSVersionChannel" "fleet-default" "").items }}
{{ if and (eq (index $channel.metadata.labels "app.kubernetes.io/managed-by") "Helm") (ne $channel.metadata.name $defChannelName) }}
---
apiVersion: elemental.cattle.io/v1beta1
kind: ManagedOSVersionChannel
metadata:
name: {{ $channel.metadata.name }}
namespace: fleet-default
spec:
options:
image: {{ $channel.spec.options.image }}
type: custom
{{ end }}
{{ end }}
4 changes: 4 additions & 0 deletions .obs/chartfile/operator/templates/validate-install-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
{{- if eq $crdrelease $.Release.Name -}}
{{- required "Elemental CRDs should be moved to the new elemental-operator-crds chart before upgrading this operator." "" -}}
{{- end -}}
{{- $crdversion := index $crdobj.metadata.annotations "app.kubernetes.io/version" -}}
{{- if or (not $crdversion) (ne $crdversion $.Chart.Version) -}}
{{- required "Elemental Operator CRDs chart version must match the version of this chart. Please install the corresponding CRD chart before." "" -}}
{{- end -}}
{{- end -}}
{{- end -}}
5 changes: 3 additions & 2 deletions .obs/chartfile/operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ seedImage:
imagePullPolicy: IfNotPresent

channel:
image: "%%IMG_REPO%%/rancher/elemental-channel"
tag: "%VERSION%"
name: "sl-micro-6.0-baremetal-channel"
image: "%%IMG_REPO%%/rancher/elemental-channel/sl-micro"
tag: "6.0-baremetal"

# number of operator replicas to deploy
replicas: 1
Expand Down
6 changes: 6 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ commonLabels:
release-name: '{{ .Release.Name }}'
cluster.x-k8s.io/provider: infrastructure-elemental
cluster.x-k8s.io/v1beta1: v1beta1
helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'

commonAnnotations:
app.kubernetes.io/instance: '{{ .Release.Name }}'
app.kubernetes.io/version: '{{ .Chart.Version }}'
app.kubernetes.io/part-of: 'Elemental Operator'
3 changes: 1 addition & 2 deletions controllers/managedosversionchannel_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ var _ = Describe("reconcile managed os version channel", func() {
// Re-sync is triggered to interval
res, err = r.Reconcile(ctx, reconcile.Request{NamespacedName: name})
Expect(err).ToNot(HaveOccurred())
Expect(res.RequeueAfter).To(BeNumerically("<", 1*time.Minute))
Expect(res.RequeueAfter).To(BeNumerically(">", 59*time.Second))
Expect(res.RequeueAfter).To(BeNumerically("~", 59*time.Second, 1*time.Minute))
})

It("should reconcile managed os version channel object without a type", func() {
Expand Down
58 changes: 46 additions & 12 deletions scripts/elemental-airgap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,28 @@ HAULER_REG_DUMMY_FILE="hauler-registry.txt"
: ${CHANNEL_ONLY:="false"}
: ${CHANNEL_IMAGE_NAME:="\$CHANNEL_IMAGE_NAME"}
: ${SKIP_ARCHIVE_CREATION:="false"}
: ${ALL_CHANNELS:="false"}

print_help() {
cat <<- EOF
Usage: $0 [OPTION] -r LOCAL_REGISTRY ELEMENTAL_OPERATOR_CHART
[-ac|-all-channels] add all defined ManagedOSVersionChannel.
[-c|--crds-chart] Elemental CRDS chart (if URL, will be downloaded).
[-co|--channel-only] just extract and rebuild the ManagedOSVersionChannel container image
[-cv|--chart-version] Specify the chart version (only used if passing chart as URLs).
[-co|--channel-only] just extract and rebuild the ManagedOSVersionChannel container image.
[-cv|--chart-version] specify the chart version (only used if passing chart as URLs).
[-d|--debug] enable debug output on screen.
[-i|--images path] tar.gz gernerated by docker save.
[-h|--help] Usage message.
[-ha|--hauler] Use hauler to generate the archive (an "Haul") of the Elemental "Collection".
[-h|--help] usage message.
[-ha|--hauler] use hauler to generate the archive (an "Haul") of the Elemental "Collection".
[-l|--image-list path] generated text file with the list of saved images (one image per line).
[-r|--local-registry] registry where to load the images to (used in the next steps).
[-sa|--skip-archive] put the list of images in the $CONTAINER_IMAGES_FILE but skip $CONTAINER_IMAGES_ARCHIVE creation
[-sa|--skip-archive] put the list of images in the $CONTAINER_IMAGES_FILE but skip $CONTAINER_IMAGES_ARCHIVE creation.
ELEMENTAL_OPERATOR_CHART could be either a chart tgz file or an url (in that case will be downloaded first)
it could even be 'dev', 'staging' or 'stable' to allow automatic download of the charts.
Parameters could also be set passing env vars:
ALL_CHANNELS (-ac) : $ALL_CHANNELS
CONTAINER_IMAGES_NAME : $CONTAINER_IMAGES_NAME
CONTAINER_IMAGES_FILE (-l) : $CONTAINER_IMAGES_FILE
CONTAINER_IMAGES_ARCHIVE (-i) : $CONTAINER_IMAGES_ARCHIVE
Expand Down Expand Up @@ -127,6 +130,10 @@ parse_parameters() {
fi
shift
;;
-ac|--all-channels)
ALL_CHANNELS=true
shift
;;
*)
[[ -n "$CHART_NAME_OPERATOR" ]] && exit_error "unrecognized command: $1"
CHART_NAME_OPERATOR="$1"
Expand Down Expand Up @@ -352,6 +359,7 @@ build_os_channel() {
local channel_img
local channel_tag
local channel_repo
local channel_list

log_info "Creating OS channel"
# name of the new channel container image we are going to create
Expand Down Expand Up @@ -384,28 +392,54 @@ build_os_channel() {
fi

get_chart_val channel_tag "channel.tag"
channel_list+="${channel_img}:${channel_tag} "

# we can have OS channels added in templates, so we have to sync them if needed
if [[ "$ALL_CHANNELS" == "true" ]]; then
# get all ManagedOSVersionChannel, so the already extracted one is in, we can overwrite channel_list
channel_list=$(helm template $CHART_NAME_OPERATOR \
| yq 'select(.kind=="ManagedOSVersionChannel") .spec.options.image' \
| sed -e s/\"//g -e /^---$/d 2>&1)
fi

if [[ -z "$channel_img" || -z "$channel_tag" ]]; then
if [[ -z "${channel_list// /}" ]]; then
log_info "\nWARNING: channel image not found: you will need to provide your own Elemental OS images\n"
return 0
fi
log_info "Found channel image: ${channel_img}:${channel_tag}"

TEMPDIR=$(mktemp -d)
log_debug "build channel image in $TEMPDIR"
pushd $TEMPDIR > /dev/null
# extract the channel.json
if ! docker run --entrypoint busybox ${channel_img}:${channel_tag} cat channel.json > channel.json; then
exit_error "cannot extract OS images"

# loop on the channel list
for channel in ${channel_list}; do
channel_img=${channel%:*}
channel_tag=${channel#*:}

log_info "Found channel image: ${channel_img}:${channel_tag}"

# extract the channel.json
if ! docker run --entrypoint busybox ${channel_img}:${channel_tag} cat channel.json > channel_${channel_img//\//_}.json; then
exit_error "cannot extract OS images"
fi
done

# Merge all channel_*.json files
if ! jq -s add channel_*.json > channel.json; then
exit_error "cannot merge channel json files"
fi

# write the new channel and identify OS images to save
local new_channel=""
for i in $(seq 0 20); do
local -i index=0
while true; do
local item item_type item_image item_name item_url_field
item=$(jq .[$i] channel.json)
item=$(jq .[$index] channel.json)
[[ "$item" == "null" ]] && break

# increment index
index+=1

get_json_val item_name "$item" ".metadata.name"
get_json_val item_type "$item" ".spec.type"
get_json_val item_display "$item" ".spec.metadata.displayName"
Expand Down
Loading

0 comments on commit 239f7fd

Please sign in to comment.