Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CCM/CSI migration support for Azure #1610

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions pkg/apis/kubeone/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (p CloudProviderSpec) CloudProviderInTree() bool {
// NB: The CSI migration can be supported only if KubeOne supports CSI plugin and driver
// for the provider
func (p CloudProviderSpec) CSIMigrationSupported() bool {
return p.External && (p.Openstack != nil || p.Vsphere != nil)
return p.External && (p.Azure != nil || p.Openstack != nil || p.Vsphere != nil)
}

// CSIMigrationFeatureGates returns CSI migration feature gates in form of a map
Expand All @@ -172,56 +172,62 @@ func (p CloudProviderSpec) CSIMigrationSupported() bool {
// (https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/)
// This is a KubeOneCluster function because feature gates are Kubernetes-version dependent.
func (c KubeOneCluster) CSIMigrationFeatureGates(complete bool) (map[string]bool, string, error) {
var featureGates map[string]bool

switch {
case c.CloudProvider.Azure != nil:
featureGates = map[string]bool{
"CSIMigrationAzureDisk": true,
"CSIMigrationAzureFile": true,
}
case c.CloudProvider.Openstack != nil:
featureGates := map[string]bool{
featureGates = map[string]bool{
"CSIMigrationOpenStack": true,
"ExpandCSIVolumes": true,
}

unregister := c.InTreePluginUnregisterFeatureGate()
if complete && unregister != "" {
featureGates[unregister] = true
}

return featureGates, marshalFeatureGates(featureGates), nil
case c.CloudProvider.Vsphere != nil:
featureGates := map[string]bool{
featureGates = map[string]bool{
"CSIMigrationvSphere": true,
}
default:
return nil, "", errors.New("csi migration is not supported for selected provider")
}

unregister := c.InTreePluginUnregisterFeatureGate()
if complete && unregister != "" {
featureGates[unregister] = true
if complete {
for _, u := range c.InTreePluginUnregisterFeatureGate() {
featureGates[u] = true
}

return featureGates, marshalFeatureGates(featureGates), nil
}

return nil, "", errors.New("csi migration is not supported for selected provider")
return featureGates, marshalFeatureGates(featureGates), nil
}

// CSIMigrationFeatureGates returns the name of the feature gate that's supposed to
// unregister the in-tree cloud provider.
// NB: This is a KubeOneCluster function because feature gates are Kubernetes-version dependent.
func (c KubeOneCluster) InTreePluginUnregisterFeatureGate() string {
func (c KubeOneCluster) InTreePluginUnregisterFeatureGate() []string {
lessThan21, _ := semver.NewConstraint("< 1.21.0")
ver, _ := semver.NewVersion(c.Versions.Kubernetes)

switch {
case c.CloudProvider.Azure != nil:
if lessThan21.Check(ver) {
return []string{"CSIMigrationAzureDiskComplete", "CSIMigrationAzureFileComplete"}
}
return []string{"InTreePluginAzureDiskUnregister", "InTreePluginAzureFileUnregister"}
case c.CloudProvider.Openstack != nil:
if lessThan21.Check(ver) {
return "CSIMigrationOpenStackComplete"
return []string{"CSIMigrationOpenStackComplete"}
}
return "InTreePluginOpenStackUnregister"
return []string{"InTreePluginOpenStackUnregister"}
case c.CloudProvider.Vsphere != nil:
if lessThan21.Check(ver) {
return "CSIMigrationvSphereComplete"
return []string{"CSIMigrationvSphereComplete"}
}
return "InTreePluginvSphereUnregister"
return []string{"InTreePluginvSphereUnregister"}
}

return ""
return nil
}

func marshalFeatureGates(fgm map[string]bool) string {
Expand Down
17 changes: 13 additions & 4 deletions pkg/tasks/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const (
systemdShowExecStartCMD = `systemctl show %s -p ExecStart`

kubeletInitializedCMD = `test -f /etc/kubernetes/kubelet.conf`

k8sAppLabel = "k8s-app"
)

var KubeProxyObjectKey = dynclient.ObjectKey{
Expand Down Expand Up @@ -590,21 +592,28 @@ func detectCCMMigrationStatus(s *state.State) (*state.CCMStatus, error) {
status.CSIMigrationEnabled = true
}
unregister := s.Cluster.InTreePluginUnregisterFeatureGate()
if unregister != "" && strings.Contains(c, fmt.Sprintf("%s=true", unregister)) {

foundUnregister := 0
for _, u := range unregister {
if strings.Contains(c, fmt.Sprintf("%s=true", u)) {
foundUnregister++
}
}
if len(unregister) > 0 && foundUnregister == len(unregister) {
status.InTreeCloudProviderUnregistered = true
}
}
}
}

ccmLabel := ""
ccmLabel := k8sAppLabel
ccmLabelValue := ""
switch {
case s.Cluster.CloudProvider.Azure != nil:
ccmLabelValue = "azure-cloud-controller-manager"
case s.Cluster.CloudProvider.Openstack != nil:
ccmLabel = "k8s-app"
ccmLabelValue = "openstack-cloud-controller-manager"
case s.Cluster.CloudProvider.Vsphere != nil:
ccmLabel = "k8s-app"
ccmLabelValue = "vsphere-cloud-controller-manager"
default:
status.ExternalCCMDeployed = false
Expand Down