fix the gce info shown in kops get cmd and set node-tag ginkgo flag

This commit is contained in:
upodroid 2023-12-03 11:41:45 +00:00
parent f95b92eb73
commit 1a593e4f6f
5 changed files with 48 additions and 12 deletions

View File

@ -60,6 +60,7 @@ type renderableCloudInstance struct {
Status string `json:"status"`
Roles []string `json:"roles"`
InternalIP string `json:"internalIP"`
ExternalIP string `json:"externalIP"`
InstanceGroup string `json:"instanceGroup"`
MachineType string `json:"machineType"`
State string `json:"state"`
@ -182,6 +183,9 @@ func instanceOutputTable(instances []*cloudinstances.CloudInstance, out io.Write
t.AddColumn("INTERNAL-IP", func(i *cloudinstances.CloudInstance) string {
return i.PrivateIP
})
t.AddColumn("EXTERNAL-IP", func(i *cloudinstances.CloudInstance) string {
return i.ExternalIP
})
t.AddColumn("INSTANCE-GROUP", func(i *cloudinstances.CloudInstance) string {
return i.CloudInstanceGroup.HumanName
})
@ -192,7 +196,7 @@ func instanceOutputTable(instances []*cloudinstances.CloudInstance, out io.Write
return string(i.State)
})
columns := []string{"ID", "NODE-NAME", "STATUS", "ROLES", "STATE", "INTERNAL-IP", "INSTANCE-GROUP", "MACHINE-TYPE"}
columns := []string{"ID", "NODE-NAME", "STATUS", "ROLES", "STATE", "INTERNAL-IP", "EXTERNAL-IP", "INSTANCE-GROUP", "MACHINE-TYPE"}
return t.Render(instances, out, columns...)
}
@ -220,6 +224,7 @@ func asRenderable(instances []*cloudinstances.CloudInstance) []*renderableCloudI
Status: ci.Status,
Roles: ci.Roles,
InternalIP: ci.PrivateIP,
ExternalIP: ci.ExternalIP,
InstanceGroup: ci.CloudInstanceGroup.HumanName,
MachineType: ci.MachineType,
State: string(ci.State),

View File

@ -40,7 +40,7 @@ type CloudInstance struct {
Node *v1.Node
// CloudInstanceGroup is the managing CloudInstanceGroup
CloudInstanceGroup *CloudInstanceGroup
// Status indicates if the instance has joined the cluster and if it needs any updates.
// Status indicates the state of instance is in as reported by the Cloud APIs
Status string
// Roles are the roles the instance have.
Roles []string
@ -48,6 +48,8 @@ type CloudInstance struct {
MachineType string
// Private IP is the private ip address of the instance.
PrivateIP string
// State is in which state the instance is in
// External IP is the public ip address of the instance.
ExternalIP string
// State indicates if the instance has joined the cluster and if it needs any updates.
State State
}

View File

@ -203,6 +203,9 @@ func (t *Tester) addNodeIG() error {
ig = v
}
}
nodeTag := gce.TagForRole(cluster.ObjectMeta.Name, unversioned.InstanceGroupRoleNode)
klog.Infof("Setting --node-tag=%s", nodeTag)
t.TestArgs += " --node-tag=" + nodeTag
igName := gce.NameForInstanceGroupManager(cluster.ObjectMeta.Name, ig.ObjectMeta.Name, ig.Spec.Zones[0])
klog.Infof("Setting --node-instance-group=%s", igName)
t.TestArgs += " --node-instance-group=" + igName

View File

@ -1281,24 +1281,19 @@ func buildCloudInstance(i *autoscaling.Instance, instances map[string]*ec2.Insta
func addCloudInstanceData(cm *cloudinstances.CloudInstance, instance *ec2.Instance) {
cm.MachineType = aws.StringValue(instance.InstanceType)
isControlPlane := false
for _, tag := range instance.Tags {
key := aws.StringValue(tag.Key)
if !strings.HasPrefix(key, TagNameRolePrefix) {
continue
}
role := strings.TrimPrefix(key, TagNameRolePrefix)
cm.PrivateIP = aws.StringValue(instance.PrivateIpAddress)
if role == "master" || role == "control-plane" {
isControlPlane = true
cm.Roles = append(cm.Roles, "control-plane")
} else {
cm.Roles = append(cm.Roles, role)
cm.PrivateIP = aws.StringValue(instance.PrivateIpAddress)
}
}
if isControlPlane {
cm.Roles = append(cm.Roles, "control-plane")
cm.PrivateIP = aws.StringValue(instance.PrivateIpAddress)
}
}
func findInstances(c AWSCloud, ig *kops.InstanceGroup) (map[string]*ec2.Instance, error) {

View File

@ -28,6 +28,7 @@ import (
"k8s.io/klog/v2"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/cloudinstances"
"k8s.io/kops/upup/pkg/fi"
)
// DeleteGroup deletes a cloud of instances controlled by an Instance Group Manager
@ -171,13 +172,18 @@ func getCloudGroups(c GCECloud, cluster *kops.Cluster, instancegroups []*kops.In
for _, i := range instances {
id := i.Instance
name := LastComponent(id)
instance, err := c.Compute().Instances().Get(project, zoneName, name)
if err != nil {
return nil, fmt.Errorf("error getting Instance: %v", err)
}
cm := &cloudinstances.CloudInstance{
ID: id,
ID: instance.SelfLink,
CloudInstanceGroup: g,
}
addCloudInstanceData(cm, instance)
// Try first by provider ID
name := LastComponent(id)
providerID := "gce://" + project + "/" + zoneName + "/" + name
node := nodesByProviderID[providerID]
@ -257,3 +263,28 @@ func matchInstanceGroup(mig *compute.InstanceGroupManager, c *kops.Cluster, inst
}
return matches[0], nil
}
func addCloudInstanceData(cm *cloudinstances.CloudInstance, instance *compute.Instance) {
cm.MachineType = LastComponent(instance.MachineType)
cm.Status = instance.Status
if instance.Status == "RUNNING" {
cm.State = cloudinstances.CloudInstanceStatusUpToDate
}
for k := range instance.Labels {
if !strings.HasPrefix(k, GceLabelNameRolePrefix) {
continue
}
role := strings.TrimPrefix(k, GceLabelNameRolePrefix)
// A VM must have one network interface and at most a single AccessConfig on an network interface
// Also kops doesn't support MultiNics
cm.PrivateIP = fi.ValueOf(&instance.NetworkInterfaces[0].NetworkIP)
if len(instance.NetworkInterfaces[0].AccessConfigs) == 1 {
cm.ExternalIP = fi.ValueOf(&instance.NetworkInterfaces[0].AccessConfigs[0].NatIP)
}
if role == "master" || role == "control-plane" {
cm.Roles = append(cm.Roles, "control-plane")
} else {
cm.Roles = append(cm.Roles, role)
}
}
}