Skip to content

Conversation

@trawler
Copy link

@trawler trawler commented Oct 17, 2018

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 17, 2018
@trawler trawler requested review from enxebre and frobware October 17, 2018 16:17
@trawler trawler changed the title Drop duplicate instance tags, if exists [WIP] Drop duplicate instance tags, if exists Oct 17, 2018
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 17, 2018
@trawler trawler changed the title [WIP] Drop duplicate instance tags, if exists Drop duplicate instance tags, if exists Oct 17, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to == true.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, I think, can be reduced to:

    ...
    keys := make(map[string]bool)
    result := []*ec2.Tag{}
    for _, entry := range tags {
        if _, value := keys[*entry.Key]; !value {
            keys[*entry.Key] = true
            result = append(result, entry)
        }
    }    
    return result
}

but untested - I just typed it out!

Please could you also create a unit test for this function as it it generic.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, I think, can be reduced to:

    ...
    keys := make(map[string]bool)
    result := []*ec2.Tag{}
    for _, entry := range tags {
        if _, value := keys[*entry.Key]; !value {
            keys[*entry.Key] = true
            result = append(result, entry)
        }
    }    
    return result
}

but untested - I just typed it out!

Please could you also create a unit test for this function as it it generic.

Copy link
Member

@enxebre enxebre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great! can we please include a unit test for this?

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 19, 2018
@paulfantom
Copy link

/test e2e-aws

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length doesn't guarantee correctness. Better to have expected and actual and use reflect.DeepEquals to verify the result.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the empty case (i.e., empty slices).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more succinct to reduce all of this output to just:

t.Errorf("test #%d: expected %+v, got %+v", c.expected, actual)

as the inputs are quite small.

rawTagList = append(rawTagList, &ec2.Tag{Key: aws.String(tag.Name), Value: aws.String(tag.Value)})
}
tagList = append(tagList, []*ec2.Tag{
rawTagList = append(rawTagList, []*ec2.Tag{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just put all the tags under a map and then check if the key already exists?

tagMap := make(map[string]struct{})
for _, tag := range machineProviderConfig.Tags {
 		tagMap[tag.Name] = struct{}{}
}
if _, exists := tagMap["clusterid"]; !exists {
 		tagList = append(tagList, {Key: aws.String("clusterid"), Value: aws.String(clusterID)}}
}
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally I like current implementation. It prevents also from injecting duplications @frobware wdyt?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of prefer the de-dupe phase. It's easier to rationalise. I have a bunch of tags, then a last action is to de-dupe them.

@enxebre
Copy link
Member

enxebre commented Oct 23, 2018

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 23, 2018
@frobware
Copy link

/lgtm

@frobware
Copy link

/approve

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: frobware

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 23, 2018
@openshift-merge-robot openshift-merge-robot merged commit 8f8c43e into openshift:master Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants