Skip to content

Commit

Permalink
[v1.6.x] Add managedosversion finalizer (#775 & #784) (#782)
Browse files Browse the repository at this point in the history
* Add managedosversion finalizer (#775)

* Implement ManagedOSVersion controller and finalizer

Signed-off-by: Andrea Mazzotti <[email protected]>

* Remove unused ManagedOSVersion Status

Signed-off-by: Andrea Mazzotti <[email protected]>

* Block reinstall if crds are still pending to be deleted (#784)

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

---------

Signed-off-by: Andrea Mazzotti <[email protected]>
Signed-off-by: David Cassany <[email protected]>
  • Loading branch information
anmazzotti authored Jun 27, 2024
1 parent d745f7d commit a916d43
Show file tree
Hide file tree
Showing 14 changed files with 382 additions and 865 deletions.
426 changes: 0 additions & 426 deletions .obs/chartfile/crds/templates/crds.yaml

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions .obs/chartfile/crds/templates/validate-no-pending-deletions.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{{- $inventoryCRD := lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" .Release.Namespace "machineinventories.elemental.cattle.io" -}}
{{- if $inventoryCRD -}}
{{- if $inventoryCRD.metadata.deletionTimestamp -}}
{{- required "CRDs from previous installations are pending to be removed (deletionTimestamp is set). Fully deleting them before (re-)installing is required" "" -}}
{{- $crds := list
"machineinventories.elemental.cattle.io"
"machineinventoryselectors.elemental.cattle.io"
"machineinventoryselectortemplates.elemental.cattle.io"
"machineregistrations.elemental.cattle.io"
"managedosimages.elemental.cattle.io"
"managedosversionchannels.elemental.cattle.io"
"managedosversions.elemental.cattle.io"
"seedimages.elemental.cattle.io"
"metadata.elemental.cattle.io"
-}}
{{- range $index, $crd := $crds -}}
{{- $obj := lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" $.Release.Namespace $crd -}}
{{- if and $obj $obj.metadata.deletionTimestamp -}}
{{- required "CRDs from previous installations are pending to be removed (deletionTimestamp is set). Fully deleting them before (re-)installing is required" "" -}}
{{- end -}}
{{- end -}}
1 change: 1 addition & 0 deletions .obs/chartfile/operator/templates/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ rules:
- managedosversions/status
verbs:
- get
- list
- patch
- update
- apiGroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"elemental.cattle.io/v1beta1/ManagedOSVersionChannel" "managedosversionchannels"
"elemental.cattle.io/v1beta1/ManagedOSVersion" "managedosversions"
"elemental.cattle.io/v1beta1/SeedImage" "seedimages"
"elemental.cattle.io/v1beta1/Metadata" "metadata"
}}
{{- range $api, $crd := $apis -}}
{{- if not ($.Capabilities.APIVersions.Has $api) -}}
Expand Down
3 changes: 3 additions & 0 deletions api/v1beta1/common_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const (
// ElementalManagedLabel label used to put on resources managed by the elemental operator.
ElementalManagedLabel = "elemental.cattle.io/managed"

// ElementalManagedOSImageVersionNameLabel label is used to filter ManagedOSImages referencing a ManagedOSVersion.
ElementalManagedOSImageVersionNameLabel = "elemental.cattle.io/managed-os-version-name"

// ElementalManagedOSVersionChannelLabel is used to filter a set of ManagedOSVersions given the channel they originate from.
ElementalManagedOSVersionChannelLabel = "elemental.cattle.io/channel"

Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/machineinventory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
const (
MachineInventoryFinalizer = "machineinventory.elemental.cattle.io"
PlanSecretType corev1.SecretType = "elemental.cattle.io/plan"
PlanTypeAnnotation = "elemental.cattle.io/plan.type"
Expand Down
10 changes: 4 additions & 6 deletions api/v1beta1/managedosversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"strings"

"github.com/rancher/elemental-operator/pkg/object"
fleetv1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
upgradev1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)

const (
containerType = "container"
isoType = "iso"
containerType = "container"
isoType = "iso"
ManagedOSVersionFinalizer = "managedosversion.elemental.cattle.io"
)

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -59,9 +59,7 @@ type ManagedOSVersionSpec struct {
UpgradeContainer *upgradev1.ContainerSpec `json:"upgradeContainer,omitempty"`
}

type ManagedOSVersionStatus struct {
fleetv1.BundleStatus `json:""` //nolint
}
type ManagedOSVersionStatus struct{}

// +kubebuilder:object:root=true

Expand Down
3 changes: 1 addition & 2 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cmd/operator/operator/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,10 @@ func setupReconcilers(mgr ctrl.Manager, config *rootConfig) {
setupLog.Error(err, "unable to create reconciler", "controller", "SeedImage")
os.Exit(1)
}
if err := (&controllers.ManagedOSVersionReconciler{
Client: mgr.GetClient(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create reconciler", "controller", "ManagedOSVersion")
os.Exit(1)
}
}
Loading

0 comments on commit a916d43

Please sign in to comment.