Skip to content
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

implement service level labels #82

Merged
merged 1 commit into from
May 17, 2017

Conversation

concaf
Copy link
Collaborator

@concaf concaf commented Mar 27, 2017

Fixes #23

@concaf concaf mentioned this pull request Mar 27, 2017
@@ -31,6 +33,7 @@ type Container struct {
type Service struct {
Name string
Containers []Container
Labels Label
Copy link
Contributor

@surajssd surajssd Apr 4, 2017

Choose a reason for hiding this comment

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

in object.go all the types are made of builtin types as opposed to ones like this! I think @tnozicka can shade more light on it!

What I mean here is that do Labels map[string]string as opposed to Labels Label

Copy link
Member

Choose a reason for hiding this comment

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

I think this is correct.

@@ -22,6 +22,8 @@ type EnvVariable struct {
Value string
}

type Label map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this definition in encoding.go

Copy link
Member

Choose a reason for hiding this comment

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

This should be here, that is correct.
But just rename it to Labels, so it reflects that this holds multiple labels.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed

case *api_v1.Service:
transformerUtil.ApplyOpenComposeLabelsToProvider(&service.Labels, &t.ObjectMeta.Labels)
case *ext_v1beta1.Deployment:
transformerUtil.ApplyOpenComposeLabelsToProvider(&service.Labels, &t.ObjectMeta.Labels)
Copy link
Contributor

@surajssd surajssd Apr 4, 2017

Choose a reason for hiding this comment

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

I don't know a better way of doing this, the only problem with this method is that it causes problems like we had in kompose. If new k8s object generation support is added and if label application is not done here for that object we now have inconsistent objects generated, which is again hard to test.

If there is an alternate generic method to do this I would love to see that, which wil save us from mistakes in future.

@tnozicka @kadel can suggest a better way of doing it?

Copy link
Contributor

@surajssd surajssd Apr 4, 2017

Choose a reason for hiding this comment

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

Even if we need to do this, we need to design it in such a way that every k8s object should satisfy some form of interface that applies labels.

So that it is enforced and we won't have any inconsistencies.

Copy link
Member

Choose a reason for hiding this comment

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

I think that adding lables to objects should be handled in functions that are responsible for creating those objects. eg CreateServices and CreateDeployments

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved to Create* methods

@@ -22,6 +22,8 @@ type EnvVariable struct {
Value string
}

type Label map[string]string
Copy link
Member

Choose a reason for hiding this comment

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

This should be here, that is correct.
But just rename it to Labels, so it reflects that this holds multiple labels.

@@ -31,6 +33,7 @@ type Container struct {
type Service struct {
Name string
Containers []Container
Labels Label
Copy link
Member

Choose a reason for hiding this comment

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

I think this is correct.

@@ -151,6 +151,19 @@ func (raw *EnvVariable) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}

type Label map[string]string
Copy link
Member

Choose a reason for hiding this comment

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

this should reference Label type from object package.
type Label object.Label

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@concaf concaf force-pushed the add_label_support branch from 48f93ae to 33ca615 Compare April 6, 2017 07:54
@kadel
Copy link
Member

kadel commented Apr 6, 2017

Don't forget about labels in PodTemplateSpec inside Deployment. This label should be propagated down to Pod level.

@concaf concaf force-pushed the add_label_support branch from 33ca615 to 45c4192 Compare April 7, 2017 12:10
@surajssd
Copy link
Contributor

for validating if the label value is right you can use the validation function IsValidLabelValue, use this because there is a doc that specifies what qualifies as a label and what does not.

@concaf concaf force-pushed the add_label_support branch 2 times, most recently from 0e5a26e to dcf2d20 Compare April 13, 2017 10:20
@concaf concaf changed the title [WIP] implement service level labels implement service level labels Apr 13, 2017
@concaf
Copy link
Collaborator Author

concaf commented Apr 13, 2017

@surajssd thanks for pointing that out 👍

I have added the validation, validation tests, tests in encoding_test.go, PTAL!
@surajssd @kadel

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

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

two small changes, otherwise lgtm

Labels: map[string]string{
"service": o.Name,
},
Labels: *util.MergeMaps(
Copy link
Member

Choose a reason for hiding this comment

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

I would swap order of parameters here.

*util.MergeMaps(
  &serviceLabels,
  &map[string]string{"service": o.Name}
),

Map with "service" label should be the last as it should never be overwritten.
Its used as selector for Service and other stuff.

I would also add comment explaining that it has to be last and why is that.

Same thing in other places setting Labels

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Totally missed this somehow, fixed now. Thanks for pointing it out.

@@ -319,6 +319,35 @@ containers:
},
},
},

{
"Providing valid label strings",
Copy link
Member

Choose a reason for hiding this comment

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

You are testing whole service here.

You should add test testing (lb *Labels) UnmarshalYAML something like TestLabels_UnmarshalYAML similar to TestEnvVariable_UnmarshalYAML and others.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@concaf concaf force-pushed the add_label_support branch from 998161c to 8f648b7 Compare April 18, 2017 08:54
},
}

for _, tt := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

gofmt error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, fixed, thanks

@concaf concaf force-pushed the add_label_support branch 2 times, most recently from bf705a7 to fd4abc1 Compare May 2, 2017 14:34
pkg/util/util.go Outdated

// MergeMaps will merge the given maps, but it does not check for conflicts.
// In case of conflicting keys, the map that is provided later wins.
// TODO: add to docs about use with caution bits
Copy link
Contributor

Choose a reason for hiding this comment

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

where do you wanna add those docs to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to the developer docs, once and when we have it :)

pkg/util/util.go Outdated
@@ -69,3 +69,16 @@ func FetchURLWithRetries(url string, attempts int, duration time.Duration) ([]by

return data, err
}

// MergeMaps will merge the given maps, but it does not check for conflicts.
// In case of conflicting keys, the map that is provided later wins.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: how about In case of conflicting keys, the map that is provided later overrides the previous one ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ack, fixed

Copy link
Contributor

@surajssd surajssd left a comment

Choose a reason for hiding this comment

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

Add docs about the support of this in the file ref. Also add an example of this in examples folder.

@surajssd
Copy link
Contributor

surajssd commented May 5, 2017

Functionality wise this works for me, @containscafeine apart from the changes requested rest LGTM

@kadel
Copy link
Member

kadel commented May 5, 2017

Add docs about the support of this in the file ref. Also add an example of this in examples folder.

Just small note. All files in examples folder should work and do something meaningful.

@concaf
Copy link
Collaborator Author

concaf commented May 8, 2017

  • rebase
  • add docs
  • add example

@kadel @surajssd fixed comments, rebased, added docs, an example, PTAL!

@concaf concaf force-pushed the add_label_support branch from fd4abc1 to 0c8abf9 Compare May 10, 2017 17:27
@concaf concaf force-pushed the add_label_support branch from 0c8abf9 to 8fb1788 Compare May 15, 2017 14:39
@surajssd
Copy link
Contributor

cool this LGTM

@kadel kadel merged commit 35a7ac7 into redhat-developer:master May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants