Skip to content
17 changes: 5 additions & 12 deletions cloudmock/aws/mockec2/dhcpoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,11 @@ func (m *MockEC2) DescribeDhcpOptions(ctx context.Context, request *ec2.Describe
for id, dhcpOptions := range m.DhcpOptions {
allFiltersMatch := true
for _, filter := range request.Filters {
match := false
switch *filter.Name {
// case "vpc-id":
// if *subnet.main.VpcId == *filter.Values[0] {
// match = true
// }
default:
if strings.HasPrefix(*filter.Name, "tag:") {
match = m.hasTag(ec2types.ResourceTypeDhcpOptions, *dhcpOptions.DhcpOptionsId, filter)
} else {
return nil, fmt.Errorf("unknown filter name: %q", *filter.Name)
}
var match bool
if strings.HasPrefix(*filter.Name, "tag:") {
match = m.hasTag(ec2types.ResourceTypeDhcpOptions, *dhcpOptions.DhcpOptionsId, filter)
} else {
return nil, fmt.Errorf("unknown filter name: %q", *filter.Name)
}

if !match {
Expand Down
34 changes: 18 additions & 16 deletions cloudmock/aws/mockec2/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,32 @@ func (m *MockEC2) CreateTags(ctx context.Context, request *ec2.CreateTagsInput,

func (m *MockEC2) addTags(resourceId string, tags ...ec2types.Tag) {
var resourceType ec2types.ResourceType
if strings.HasPrefix(resourceId, "subnet-") {
switch {
case strings.HasPrefix(resourceId, "subnet-"):
resourceType = ec2types.ResourceTypeSubnet
} else if strings.HasPrefix(resourceId, "vpc-") {
case strings.HasPrefix(resourceId, "vpc-"):
resourceType = ec2types.ResourceTypeVpc
} else if strings.HasPrefix(resourceId, "sg-") {
case strings.HasPrefix(resourceId, "sg-"):
resourceType = ec2types.ResourceTypeSecurityGroup
} else if strings.HasPrefix(resourceId, "vol-") {
case strings.HasPrefix(resourceId, "vol-"):
resourceType = ec2types.ResourceTypeVolume
} else if strings.HasPrefix(resourceId, "igw-") {
case strings.HasPrefix(resourceId, "igw-"):
resourceType = ec2types.ResourceTypeInternetGateway
} else if strings.HasPrefix(resourceId, "eigw-") {
case strings.HasPrefix(resourceId, "eigw-"):
resourceType = ec2types.ResourceTypeEgressOnlyInternetGateway
} else if strings.HasPrefix(resourceId, "nat-") {
case strings.HasPrefix(resourceId, "nat-"):
resourceType = ec2types.ResourceTypeNatgateway
} else if strings.HasPrefix(resourceId, "dopt-") {
case strings.HasPrefix(resourceId, "dopt-"):
resourceType = ec2types.ResourceTypeDhcpOptions
} else if strings.HasPrefix(resourceId, "rtb-") {
case strings.HasPrefix(resourceId, "rtb-"):
resourceType = ec2types.ResourceTypeRouteTable
} else if strings.HasPrefix(resourceId, "eipalloc-") {
case strings.HasPrefix(resourceId, "eipalloc-"):
resourceType = ec2types.ResourceTypeElasticIp
} else if strings.HasPrefix(resourceId, "lt-") {
case strings.HasPrefix(resourceId, "lt-"):
resourceType = ec2types.ResourceTypeLaunchTemplate
} else if strings.HasPrefix(resourceId, "key-") {
case strings.HasPrefix(resourceId, "key-"):
resourceType = ec2types.ResourceTypeKeyPair
} else {
default:
klog.Fatalf("Unknown resource-type in create tags: %v", resourceId)
}
for _, tag := range tags {
Expand All @@ -83,7 +84,8 @@ func (m *MockEC2) addTags(resourceId string, tags ...ec2types.Tag) {

func (m *MockEC2) hasTag(resourceType ec2types.ResourceType, resourceId string, filter ec2types.Filter) bool {
name := *filter.Name
if strings.HasPrefix(name, "tag:") {
switch {
case strings.HasPrefix(name, "tag:"):
tagKey := name[4:]

for _, tag := range m.Tags {
Expand All @@ -103,7 +105,7 @@ func (m *MockEC2) hasTag(resourceType ec2types.ResourceType, resourceId string,
}
}
}
} else if name == "tag-key" {
case name == "tag-key":
for _, tag := range m.Tags {
if *tag.ResourceId != resourceId {
continue
Expand All @@ -117,7 +119,7 @@ func (m *MockEC2) hasTag(resourceType ec2types.ResourceType, resourceId string,
}
}
}
} else {
default:
klog.Fatalf("Unsupported filter: %v", filter)
}
return false
Expand Down
13 changes: 5 additions & 8 deletions cloudmock/aws/mockec2/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,11 @@ func (m *MockEC2) DescribeVolumes(ctx context.Context, request *ec2.DescribeVolu
for _, volume := range m.Volumes {
allFiltersMatch := true
for _, filter := range request.Filters {
match := false
switch *filter.Name {
default:
if strings.HasPrefix(*filter.Name, "tag:") {
match = m.hasTag(ec2types.ResourceTypeVolume, *volume.VolumeId, filter)
} else {
return nil, fmt.Errorf("unknown filter name: %q", *filter.Name)
}
var match bool
if strings.HasPrefix(*filter.Name, "tag:") {
match = m.hasTag(ec2types.ResourceTypeVolume, *volume.VolumeId, filter)
} else {
return nil, fmt.Errorf("unknown filter name: %q", *filter.Name)
}

if !match {
Expand Down
3 changes: 2 additions & 1 deletion cloudmock/aws/mockelbv2/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func (m *MockELBV2) AddTags(ctx context.Context, request *elbv2.AddTagsInput, op
}
if !found {
tags := m.Tags[arn]
tags.Tags = append(m.Tags[arn].Tags, reqTag)
tags.Tags = append(tags.Tags, reqTag)
m.Tags[arn] = tags
}
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions cloudmock/aws/mockelbv2/targetgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ func (m *MockELBV2) DescribeTargetGroups(ctx context.Context, request *elbv2.Des
var tgs []elbv2types.TargetGroup
for _, tg := range m.TargetGroups {
match := false

if len(request.TargetGroupArns) > 0 {
switch {
case len(request.TargetGroupArns) > 0:
for _, name := range request.TargetGroupArns {
if aws.ToString(tg.description.TargetGroupArn) == name {
match = true
}
}
} else if request.LoadBalancerArn != nil {
case request.LoadBalancerArn != nil:
if len(tg.description.LoadBalancerArns) > 0 && tg.description.LoadBalancerArns[0] == aws.ToString(request.LoadBalancerArn) {
match = true
}
} else if len(request.Names) > 0 {
case len(request.Names) > 0:
for _, name := range request.Names {
if aws.ToString(tg.description.TargetGroupName) == name {
match = true
}
}
} else {
default:
match = true
}

Expand Down
2 changes: 1 addition & 1 deletion cloudmock/openstack/mockcompute/instanceactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type instanceActionsResponse struct {
}

func (m *MockClient) mockInstanceActions() {
//re := regexp.MustCompile(`/servers/(.*?)/os-instance-actions/?`)
// re := regexp.MustCompile(`/servers/(.*?)/os-instance-actions/?`)

handler := func(w http.ResponseWriter, r *http.Request) {
m.mutex.Lock()
Expand Down
9 changes: 5 additions & 4 deletions cloudmock/openstack/mockdns/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ func (m *MockClient) mockZones() {
zoneName = r.Form.Get("name")
switch r.Method {
case http.MethodGet:
if zoneID == "" && zoneName == "" {
switch {
case zoneID == "" && zoneName == "":
// /zones
m.listZones(w)
} else if len(parts) == 3 && parts[2] == "recordsets" {
case len(parts) == 3 && parts[2] == "recordsets":
// /zones/<zoneid>/recordsets
m.listRecordSets(w, zoneID)
} else if len(parts) == 4 && parts[2] == "recordsets" {
case len(parts) == 4 && parts[2] == "recordsets":
// /zones/<zoneid>/recordsets/<recordsetid>
m.getRecordSet(w, zoneID, parts[3])
} else {
default:
// /zones?name=<zonename>
m.getZone(w, zoneName)
}
Expand Down
10 changes: 5 additions & 5 deletions cloudmock/scaleway/mockdns/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ func (f *FakeDomainAPI) ListDNSZoneRecords(req *domain.ListDNSZoneRecordsRequest

func (f *FakeDomainAPI) UpdateDNSZoneRecords(req *domain.UpdateDNSZoneRecordsRequest, opts ...scw.RequestOption) (*domain.UpdateDNSZoneRecordsResponse, error) {
for _, change := range req.Changes {

if change.Add != nil {
switch {
case change.Add != nil:
for _, toAdd := range change.Add.Records {
toAdd.ID = uuid.New().String()
f.Records[toAdd.Name] = toAdd
}

} else if change.Set != nil {
case change.Set != nil:
if len(change.Set.Records) != 1 {
fmt.Printf("only 1 record change will be applied from %d changes requested", len(change.Set.Records))
}
Expand All @@ -98,7 +98,7 @@ func (f *FakeDomainAPI) UpdateDNSZoneRecords(req *domain.UpdateDNSZoneRecordsReq
toUpsert.ID = *change.Set.ID
f.Records[toUpsert.Name] = toUpsert
}
} else if change.Delete != nil {
case change.Delete != nil:
found := false
for name, record := range f.Records {
if record.ID == *change.Delete.ID {
Expand All @@ -111,7 +111,7 @@ func (f *FakeDomainAPI) UpdateDNSZoneRecords(req *domain.UpdateDNSZoneRecordsReq
return nil, fmt.Errorf("could not find record %s to delete", *change.Delete.ID)
}

} else {
default:
return nil, fmt.Errorf("mock DNS not implemented for this method")
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops-controller/controllers/hosts_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *HostsReconciler) updateHosts(ctx context.Context, endpointsList *corev1
}
suffix := ".internal." + r.clusterName
if !strings.HasSuffix(hostname, suffix) {
hostname = hostname + suffix
hostname += suffix
} else {
klog.Warningf("endpoints %s/%s found with full internal name for discovery label %q; use short name %q instead", endpoints.Name, endpoints.Namespace, kops.DiscoveryLabelKey, strings.TrimSuffix(hostname, suffix))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewRoute53APIStub() *Route53APIStub {

func (r *Route53APIStub) ListResourceRecordSets(ctx context.Context, input *route53.ListResourceRecordSetsInput, optFns ...func(*route53.Options)) (*route53.ListResourceRecordSetsOutput, error) {
output := &route53.ListResourceRecordSetsOutput{} // TODO: Support optional input args.
if len(r.recordSets) <= 0 {
if len(r.recordSets) == 0 {
output.ResourceRecordSets = []route53types.ResourceRecordSet{}
} else if _, ok := r.recordSets[*input.HostedZoneId]; !ok {
output.ResourceRecordSets = []route53types.ResourceRecordSet{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kops/v1alpha2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const GroupName = "kops.k8s.io"
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}

//// Kind takes an unqualified kind and returns a Group qualified GroupKind
//func Kind(kind string) schema.GroupKind {
// func Kind(kind string) schema.GroupKind {
// return SchemeGroupVersion.WithKind(kind).GroupKind()
//}
//
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kops/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const GroupName = "kops.k8s.io"
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha3"}

//// Kind takes an unqualified kind and returns a Group qualified GroupKind
//func Kind(kind string) schema.GroupKind {
// func Kind(kind string) schema.GroupKind {
// return SchemeGroupVersion.WithKind(kind).GroupKind()
//}
//
Expand Down
7 changes: 4 additions & 3 deletions pkg/apis/nodeup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,12 @@ func NewConfig(cluster *kops.Cluster, instanceGroup *kops.InstanceGroup) (*Confi

config.Openstack = cluster.Spec.CloudProvider.Openstack

if instanceGroup.Spec.UpdatePolicy != nil {
switch {
case instanceGroup.Spec.UpdatePolicy != nil:
config.UpdatePolicy = *instanceGroup.Spec.UpdatePolicy
} else if cluster.Spec.UpdatePolicy != nil {
case cluster.Spec.UpdatePolicy != nil:
config.UpdatePolicy = *cluster.Spec.UpdatePolicy
} else {
default:
config.UpdatePolicy = kops.UpdatePolicyAutomatic
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/dump/resourcedumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ func (d *resourceDumper) dumpGVRNamespaces(ctx context.Context, jobs chan gvrNam
}

func maskObject(obj runtime.Object) error {
switch obj.GetObjectKind().GroupVersionKind() {
case schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"}:
if obj.GetObjectKind().GroupVersionKind() == (schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"}) {
unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
return err
Expand Down
11 changes: 7 additions & 4 deletions pkg/kopscontrollerclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,19 @@ func (b *Client) Query(ctx context.Context, req any, resp any) error {
if err != nil {
return err
}
if response.Body != nil {
defer response.Body.Close()
}

// if we receive StatusConflict it means that we should exit gracefully
if response.StatusCode == http.StatusConflict {
klog.Infof("kops-controller returned status code %d", response.StatusCode)
if response.Body != nil {
response.Body.Close()
}
os.Exit(0)
}

if response.Body != nil {
defer response.Body.Close()
}

if response.StatusCode != http.StatusOK {
detail := ""
if response.Body != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/gcemodel/api_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (b *APILoadBalancerBuilder) createInternalLB(c *fi.CloudupModelBuilderConte
},
}
// We previously created a forwarding rule which was external; prune it
fr.PruneForwardingRulesWithName(b.NameForForwardingRule("kops-controller")) //, "Removing legacy external load balancer for kops-controller")
fr.PruneForwardingRulesWithName(b.NameForForwardingRule("kops-controller")) // , "Removing legacy external load balancer for kops-controller")

c.AddTask(fr)
}
Expand Down
15 changes: 6 additions & 9 deletions pkg/model/gcemodel/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB
sortedLabelKeys[i] = k
i++
}
slices.SortStableFunc(sortedLabelKeys, func(a, b string) int {
return strings.Compare(a, b)
})
slices.SortStableFunc(sortedLabelKeys, strings.Compare)
for _, k := range sortedLabelKeys {
nodeLabels += k + "=" + ig.Spec.NodeLabels[k] + ","
}
Expand Down Expand Up @@ -233,11 +231,11 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB

t.ServiceAccounts = append(t.ServiceAccounts, b.LinkToServiceAccount(ig))

//labels, err := b.CloudTagsForInstanceGroup(ig)
//if err != nil {
// labels, err := b.CloudTagsForInstanceGroup(ig)
// if err != nil {
// return fmt.Errorf("error building cloud tags: %v", err)
//}
//t.Labels = labels
// }
// t.Labels = labels

t.GuestAccelerators = []gcetasks.AcceleratorConfig{}
for _, accelerator := range ig.Spec.GuestAccelerators {
Expand Down Expand Up @@ -342,8 +340,7 @@ func (b *AutoscalingGroupModelBuilder) Build(c *fi.CloudupModelBuilderContext) e
}

// Attach masters to load balancer if we're using one
switch ig.Spec.Role {
case kops.InstanceGroupRoleControlPlane:
if ig.Spec.Role == kops.InstanceGroupRoleControlPlane {
if b.UseLoadBalancerForAPI() {
lbSpec := b.Cluster.Spec.API.LoadBalancer
if lbSpec != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/model/gcemodel/storageacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func (b *StorageAclBuilder) Build(c *fi.CloudupModelBuilderContext) error {
return fmt.Errorf("cannot parse cluster path %q: %w", clusterPath, err)
}

switch p := p.(type) {
case *vfs.GSPath:
if p, ok := p.(*vfs.GSPath); ok {
// It's not ideal that we have to do this at the bucket level,
// but GCS doesn't seem to have a way to do subtrees (like AWS IAM does)
// Note this permission only lets us list objects, not read them
Expand Down
6 changes: 3 additions & 3 deletions pkg/nodeidentity/aws/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type nodeIdentifier struct {
}

// New creates and returns a nodeidentity.Identifier for Nodes running on AWS
func New(ctx context.Context, CacheNodeidentityInfo bool) (nodeidentity.Identifier, error) {
func New(ctx context.Context, cacheNodeidentityInfo bool) (nodeidentity.Identifier, error) {
config, err := awsconfig.LoadDefaultConfig(ctx, awslog.WithAWSLogger())
if err != nil {
return nil, fmt.Errorf("error loading AWS config: %v", err)
Expand All @@ -77,7 +77,7 @@ func New(ctx context.Context, CacheNodeidentityInfo bool) (nodeidentity.Identifi
return &nodeIdentifier{
ec2Client: ec2Client,
cache: expirationcache.NewTTLStore(stringKeyFunc, cacheTTL),
cacheEnabled: CacheNodeidentityInfo,
cacheEnabled: cacheNodeidentityInfo,
}, nil
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func (i *nodeIdentifier) getInstance(ctx context.Context, instanceID string) (*e
}

// @check we found some instances
if len(resp.Reservations) <= 0 || len(resp.Reservations[0].Instances) <= 0 {
if len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
return nil, fmt.Errorf("missing instance id: %s", instanceID)
}
if len(resp.Reservations[0].Instances) > 1 {
Expand Down
Loading
Loading