Skip to content

Commit

Permalink
Merge pull request openshift#192 from spangenberg/remove-clusterid-tag
Browse files Browse the repository at this point in the history
Remove clusterid tag
  • Loading branch information
openshift-merge-robot committed Apr 19, 2019
2 parents 6d47d52 + af3deb7 commit 53ba43b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
44 changes: 44 additions & 0 deletions pkg/actuators/machine/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package machine

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
)

const (
clusterFilterKeyPrefix = "kubernetes.io/cluster/"
clusterFilterValue = "owned"
)

func awsTagFilter(name string) *string {
return aws.String(fmt.Sprint("tag:", name))
}

func clusterFilterKey(name string) string {
return fmt.Sprint(clusterFilterKeyPrefix, name)
}

func clusterFilter(name string) *ec2.Filter {
return &ec2.Filter{
Name: awsTagFilter(clusterFilterKey(name)),
Values: aws.StringSlice([]string{clusterFilterValue}),
}
}
1 change: 0 additions & 1 deletion pkg/actuators/machine/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func launchInstance(machine *machinev1.Machine, machineProviderConfig *providerc
rawTagList = append(rawTagList, &ec2.Tag{Key: aws.String(tag.Name), Value: aws.String(tag.Value)})
}
rawTagList = append(rawTagList, []*ec2.Tag{
{Key: aws.String("clusterid"), Value: aws.String(clusterID)},
{Key: aws.String("kubernetes.io/cluster/" + clusterID), Value: aws.String("owned")},
{Key: aws.String("Name"), Value: aws.String(machine.Name)},
}...)
Expand Down
11 changes: 3 additions & 8 deletions pkg/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,17 @@ func getStoppedInstances(machine *machinev1.Machine, client awsclient.Client) ([
// and cluster ID.
func getInstances(machine *machinev1.Machine, client awsclient.Client, instanceStateFilter []*string) ([]*ec2.Instance, error) {

machineName := machine.Name

clusterID, ok := getClusterID(machine)
if !ok {
return []*ec2.Instance{}, fmt.Errorf("unable to get cluster ID for machine: %q", machine.Name)
}

requestFilters := []*ec2.Filter{
{
Name: aws.String("tag:Name"),
Values: []*string{&machineName},
},
{
Name: aws.String("tag:clusterid"),
Values: []*string{&clusterID},
Name: awsTagFilter("Name"),
Values: aws.StringSlice([]string{machine.Name}),
},
clusterFilter(clusterID),
}

if instanceStateFilter != nil {
Expand Down
1 change: 0 additions & 1 deletion test/machines/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ var _ = framework.SigKubeDescribe("Machines", func() {
"sub-host-type": "default",
"host-type": "master",
"Name": testMachine.Name,
"clusterid": clusterID,
}))
})

Expand Down

0 comments on commit 53ba43b

Please sign in to comment.