Skip to content

Commit

Permalink
Merge pull request rancher#35007 from StrongMonkey/add-provider-labels
Browse files Browse the repository at this point in the history
Add provider labels to v3 cluster
  • Loading branch information
StrongMonkey committed Oct 4, 2021
2 parents 0523365 + 4d9d063 commit 1874d54
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -10,6 +10,10 @@ import (
"k8s.io/client-go/kubernetes"
)

const (
providerKey = "provider.cattle.io"
)

type handler struct {
ctx context.Context
clusters v32.ClusterClient
Expand All @@ -32,7 +36,7 @@ func Register(ctx context.Context,
}

func (h *handler) OnChange(key string, cluster *v3.Cluster) (*v3.Cluster, error) {
if cluster == nil || cluster.Status.Provider != "" {
if cluster == nil || (cluster.Status.Provider != "" && cluster.Labels[providerKey] != "") {
// if cluster has windows enabled and provider is not rke.windows, continue to detect if it has windows nodes
if cluster == nil || !cluster.Spec.WindowsPreferedCluster || cluster.Status.Provider == "rke.windows" {
return cluster, nil
Expand Down Expand Up @@ -65,6 +69,10 @@ func (h *handler) OnChange(key string, cluster *v3.Cluster) (*v3.Cluster, error)
return cluster, err
}
cluster = cluster.DeepCopy()
if cluster.Labels == nil {
cluster.Labels = map[string]string{}
}
cluster.Labels[providerKey] = provider
cluster.Status.Provider = provider
return h.clusters.Update(cluster)
}

0 comments on commit 1874d54

Please sign in to comment.