-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Digital Ocean] Handle logic for kops edit/update cluster #9116
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d3f244
Changes for handling kops update
srikiz b6a197e
Update minor changes
srikiz 203449d
Minor changes for code cleanup
srikiz c68f013
Fix static checks
srikiz 4783a54
Fix govet
srikiz f46ebbc
Incorporate review comments
srikiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -32,9 +32,13 @@ import ( | |
"k8s.io/kops/pkg/apis/kops" | ||
"k8s.io/kops/pkg/cloudinstances" | ||
"k8s.io/kops/pkg/resources/digitalocean/dns" | ||
"k8s.io/kops/protokube/pkg/etcd" | ||
"k8s.io/kops/upup/pkg/fi" | ||
) | ||
|
||
const TagKubernetesClusterIndex = "k8s-index" | ||
const TagKubernetesClusterNamePrefix = "KubernetesCluster" | ||
|
||
// TokenSource implements oauth2.TokenSource | ||
type TokenSource struct { | ||
AccessToken string | ||
|
@@ -139,6 +143,10 @@ func (c *Cloud) LoadBalancers() godo.LoadBalancersService { | |
return c.Client.LoadBalancers | ||
} | ||
|
||
func (c *Cloud) GetAllLoadBalancers() ([]godo.LoadBalancer, error) { | ||
return getAllLoadBalancers(c) | ||
} | ||
|
||
// FindVPCInfo is not implemented, it's only here to satisfy the fi.Cloud interface | ||
func (c *Cloud) FindVPCInfo(id string) (*fi.VPCInfo, error) { | ||
return nil, errors.New("not implemented") | ||
|
@@ -175,3 +183,98 @@ func (c *Cloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressSta | |
|
||
return nil, nil | ||
} | ||
|
||
// FindClusterStatus discovers the status of the cluster, by looking for the tagged etcd volumes | ||
func (c *Cloud) FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error) { | ||
etcdStatus, err := findEtcdStatus(c, cluster) | ||
if err != nil { | ||
return nil, err | ||
} | ||
status := &kops.ClusterStatus{ | ||
EtcdClusters: etcdStatus, | ||
} | ||
klog.V(2).Infof("Cluster status (from cloud): %v", fi.DebugAsJsonString(status)) | ||
return status, nil | ||
} | ||
|
||
// findEtcdStatus discovers the status of etcd, by looking for the tagged etcd volumes | ||
func findEtcdStatus(c *Cloud, cluster *kops.Cluster) ([]kops.EtcdClusterStatus, error) { | ||
statusMap := make(map[string]*kops.EtcdClusterStatus) | ||
volumes, err := getAllVolumesByRegion(c, c.RegionName) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to get all volumes by region from %s: %v", c.RegionName, err) | ||
} | ||
|
||
for _, volume := range volumes { | ||
volumeID := volume.ID | ||
|
||
etcdClusterName := "" | ||
var etcdClusterSpec *etcd.EtcdClusterSpec | ||
|
||
for _, myTag := range volume.Tags { | ||
klog.V(8).Infof("findEtcdStatus status (from cloud): checking if volume with tag %q belongs to cluster", myTag) | ||
// check if volume belongs to this cluster. | ||
// tag will be in the format "KubernetesCluster:dev5-k8s-local" (where clusterName is dev5.k8s.local) | ||
clusterName := strings.Replace(cluster.Name, ".", "-", -1) | ||
if strings.Contains(myTag, fmt.Sprintf("%s:%s", TagKubernetesClusterNamePrefix, clusterName)) { | ||
klog.V(10).Infof("findEtcdStatus cluster comparison matched for tag: %v", myTag) | ||
// this volume belongs to our cluster, add this to our etcdClusterSpec. | ||
// loop through the tags again and | ||
for _, volumeTag := range volume.Tags { | ||
if strings.Contains(volumeTag, TagKubernetesClusterIndex) { | ||
volumeTagParts := strings.Split(volumeTag, ":") | ||
if len(volumeTagParts) < 2 { | ||
return nil, fmt.Errorf("volume tag split failed, too few components for tag %q on volume %q", volumeTag, volume) | ||
} | ||
dropletIndex := volumeTagParts[1] | ||
etcdClusterSpec, err = c.getEtcdClusterSpec(volume.Name, dropletIndex) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error should be handled before we log the spec in the line right above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, updated. |
||
return nil, fmt.Errorf("error parsing etcd cluster tag %q on volume %q: %v", volumeTag, volumeID, err) | ||
} | ||
|
||
klog.V(10).Infof("findEtcdStatus etcdClusterSpec: %v", fi.DebugAsJsonString(etcdClusterSpec)) | ||
etcdClusterName = etcdClusterSpec.ClusterKey | ||
status := statusMap[etcdClusterName] | ||
if status == nil { | ||
status = &kops.EtcdClusterStatus{ | ||
Name: etcdClusterName, | ||
} | ||
statusMap[etcdClusterName] = status | ||
} | ||
|
||
memberName := etcdClusterSpec.NodeName | ||
status.Members = append(status.Members, &kops.EtcdMemberStatus{ | ||
Name: memberName, | ||
VolumeId: volume.ID, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
status := make([]kops.EtcdClusterStatus, 0, len(statusMap)) | ||
for _, v := range statusMap { | ||
status = append(status, *v) | ||
} | ||
|
||
return status, nil | ||
} | ||
|
||
func (c *Cloud) getEtcdClusterSpec(volumeName string, dropletName string) (*etcd.EtcdClusterSpec, error) { | ||
var clusterKey string | ||
if strings.Contains(volumeName, "etcd-main") { | ||
clusterKey = "main" | ||
} else if strings.Contains(volumeName, "etcd-events") { | ||
clusterKey = "events" | ||
} else { | ||
return nil, fmt.Errorf("could not determine etcd cluster type for volume: %s", volumeName) | ||
} | ||
|
||
return &etcd.EtcdClusterSpec{ | ||
ClusterKey: clusterKey, | ||
NodeName: dropletName, | ||
NodeNames: []string{dropletName}, | ||
}, 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if 10 could be too high. AFAIK, level 8 is where Kubernetes tends to log very specific details at the HTTP request level. I'm not too familiar with how kops handles log levels in general, so not a super strong opinion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will keep it with 10 for now. There are lot places I had seen 10 before, and that's how I continued to use that. I'll keep a note to change this to 8 for all DO work as a separate PR at a later point.