Skip to content

Commit

Permalink
ipam: Skip cleanup for non OpenShift types on OpenShift (#1826)
Browse files Browse the repository at this point in the history
Since Certificate and Issuer are not deployed on OpenShift,
trying to clean them will fail and block the whole flow.
Filter them out from the cleaning on OpenShift.

Signed-off-by: Or Shoval <oshoval@redhat.com>
  • Loading branch information
oshoval authored Jul 7, 2024
1 parent 8f67002 commit 228da6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pkg/network/kubevirt_ipam_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ func renderKubevirtIPAMController(conf *cnao.NetworkAddonsConfigSpec, manifestDi
}

// cleanUpKubevirtIpamController checks specific kic outdated objects or ones that are no longer compatible and deletes them.
func cleanUpKubevirtIpamController(conf *cnao.NetworkAddonsConfigSpec, ctx context.Context, client k8sclient.Client) []error {
func cleanUpKubevirtIpamController(conf *cnao.NetworkAddonsConfigSpec, ctx context.Context, client k8sclient.Client, isOpenShift bool) []error {
if conf.KubevirtIpamController == nil {
return []error{}
}

errList := []error{}
errList = append(errList, cleanUpKubevirtIpamControllerOldNames(ctx, client)...)
errList = append(errList, cleanUpKubevirtIpamControllerOldNames(ctx, client, isOpenShift)...)
return errList
}

// cleanUpKubevirtIpamControllerOldNames deletes kic objects with old name after a new name was introduces in version 0.94.1
// REQUIRED_FOR upgrade from kubevirt-ipam-controller == 0.94.0
func cleanUpKubevirtIpamControllerOldNames(ctx context.Context, client k8sclient.Client) []error {
func cleanUpKubevirtIpamControllerOldNames(ctx context.Context, client k8sclient.Client, isOpenShift bool) []error {
namespace := os.Getenv("OPERAND_NAMESPACE")

resources := []struct {
Expand Down Expand Up @@ -117,6 +117,10 @@ func cleanUpKubevirtIpamControllerOldNames(ctx context.Context, client k8sclient

var errors []error
for _, resource := range resources {
if isOpenShift && resource.gvk.Group == "cert-manager.io" {
continue
}

existing := &unstructured.Unstructured{}
existing.SetGroupVersionKind(resource.gvk)

Expand Down
2 changes: 1 addition & 1 deletion pkg/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func SpecialCleanUp(conf *cnao.NetworkAddonsConfigSpec, client k8sclient.Client,
ctx := context.TODO()

errs = append(errs, cleanUpMultus(conf, ctx, client)...)
errs = append(errs, cleanUpKubevirtIpamController(conf, ctx, client)...)
errs = append(errs, cleanUpKubevirtIpamController(conf, ctx, client, clusterInfo.OpenShift4)...)
errs = append(errs, cleanUpNamespaceLabels(ctx, client)...)

if len(errs) > 0 {
Expand Down

0 comments on commit 228da6e

Please sign in to comment.