Skip to content

Commit

Permalink
Remove legacy vSphere CCM Service if exists
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
  • Loading branch information
xmudrii committed Jul 8, 2021
1 parent cfbe072 commit b3f9478
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/clientutil/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2021 The KubeOne Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package clientutil

import (
"context"

"github.com/pkg/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// DeleteIfExists makes it easy to "delete" Kubernetes objects if they exist
func DeleteIfExists(ctx context.Context, c client.Client, obj client.Object) error {
err := c.Delete(ctx, obj)

switch {
case k8serrors.IsNotFound(err):
return nil
case err != nil:
return errors.Wrapf(err, "failed to delete %T object", obj)
default:
return nil
}
}
3 changes: 3 additions & 0 deletions pkg/templates/externalccm/ccm.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func Ensure(s *state.State) error {
}
err = addons.EnsureAddonByName(s, resources.AddonCCMOpenStack)
case s.Cluster.CloudProvider.Vsphere != nil:
if mErr := migrateVsphereAddon(s); mErr != nil {
return errors.Wrap(err, "failed to migrate to vsphere addon")
}
err = addons.EnsureAddonByName(s, resources.AddonCCMVsphere)
default:
s.Logger.Infof("External CCM for %q not yet supported, skipping", s.Cluster.CloudProvider.CloudProviderName())
Expand Down
44 changes: 44 additions & 0 deletions pkg/templates/externalccm/vsphere.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2019 The KubeOne Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package externalccm

import (
"k8c.io/kubeone/pkg/clientutil"
"k8c.io/kubeone/pkg/state"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
vSphereDeploymentName = "vsphere-cloud-controller-manager"
)

func migrateVsphereAddon(s *state.State) error {
return clientutil.DeleteIfExists(s.Context, s.DynamicClient, vSphereService())
}

func vSphereService() *corev1.Service {
// We're intentionally keeping only Service metadata, as it's enough for
// deleting the object
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: vSphereDeploymentName,
Namespace: metav1.NamespaceSystem,
},
}
}

0 comments on commit b3f9478

Please sign in to comment.