-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
pkg/object/object.go
Outdated
@@ -31,6 +33,7 @@ type Container struct { | |||
type Service struct { | |||
Name string | |||
Containers []Container | |||
Labels Label |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
pkg/object/object.go
Outdated
@@ -22,6 +22,8 @@ type EnvVariable struct { | |||
Value string | |||
} | |||
|
|||
type Label map[string]string |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to Create*
methods
pkg/object/object.go
Outdated
@@ -22,6 +22,8 @@ type EnvVariable struct { | |||
Value string | |||
} | |||
|
|||
type Label map[string]string |
There was a problem hiding this comment.
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.
pkg/object/object.go
Outdated
@@ -31,6 +33,7 @@ type Container struct { | |||
type Service struct { | |||
Name string | |||
Containers []Container | |||
Labels Label |
There was a problem hiding this comment.
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.
pkg/encoding/v1/encoding.go
Outdated
@@ -151,6 +151,19 @@ func (raw *EnvVariable) UnmarshalYAML(unmarshal func(interface{}) error) error { | |||
return nil | |||
} | |||
|
|||
type Label map[string]string |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
48f93ae
to
33ca615
Compare
Don't forget about labels in |
33ca615
to
45c4192
Compare
for validating if the label value is right you can use the validation function |
0e5a26e
to
dcf2d20
Compare
There was a problem hiding this 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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
pkg/encoding/v1/encoding_test.go
Outdated
@@ -319,6 +319,35 @@ containers: | |||
}, | |||
}, | |||
}, | |||
|
|||
{ | |||
"Providing valid label strings", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
998161c
to
8f648b7
Compare
pkg/encoding/v1/encoding_test.go
Outdated
}, | ||
} | ||
|
||
for _, tt := range tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gofmt error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, fixed, thanks
bf705a7
to
fd4abc1
Compare
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack, fixed
There was a problem hiding this 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.
Functionality wise this works for me, @containscafeine apart from the changes requested rest LGTM |
Just small note. All files in examples folder should work and do something meaningful. |
cool this LGTM |
Fixes #23