-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove legacy vSphere CCM Service if exists
Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} | ||
} |