-
Notifications
You must be signed in to change notification settings - Fork 40
Conversation
Can you please add docs, and tests? |
pkg/spec/types.go
Outdated
@@ -144,6 +145,10 @@ type SecretMod struct { | |||
|
|||
// ControllerFields are the common fields in every controller Kedge supports | |||
type ControllerFields struct { | |||
// Field to specify the version of application | |||
// +optional | |||
Appversion json.Number `json:"appversion,omitempty"` |
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.
It would be better to have Appversion
as a string. We should allow appversions like 1.0.4-beta1
pkg/spec/deployment.go
Outdated
@@ -56,6 +56,9 @@ func (deployment *DeploymentSpecMod) Fix() error { | |||
|
|||
deployment.ControllerFields.ObjectMeta.Labels = addKeyValueToMap(appLabelKey, deployment.ControllerFields.Name, deployment.ControllerFields.ObjectMeta.Labels) | |||
|
|||
if deployment.ControllerFields.Appversion != "" { | |||
deployment.ControllerFields.ObjectMeta.Annotations = addKeyValueToMap("appversion", string(deployment.ControllerFields.Appversion), deployment.ControllerFields.ObjectMeta.Annotations) |
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.
appversion should be a constant. Similarly to appLabelKey
If you redefine Appversions
as a string you won't have to do type conversion
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.
We should add this label to every object created from the file.
It might be better to do this together for all objects. This could be done at the end of the CreateK8sObjects
function in the resourece.go , just before all objects are returned. You might have to do some type conversion magic to get ObjectMeta
from runtime.Object
;-)
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.
specifically this could be:
appVersion
With V
being capital
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.
just before all objects are returned. You might have to do some type conversion magic to get ObjectMeta from runtime.Object ;-)
@kadel can't we just do this label addition in each create*
function? Like before we add ObjectMeta in places [1], [2], [3].
Can we have some way where we can enforce the call of function which does addition of this label?
5563446
to
c3ebba4
Compare
appversion
pkg/spec/resources.go
Outdated
objects[i] = t | ||
case *api_v1.ConfigMap: | ||
t.ObjectMeta.Annotations = addKeyValueToMap(appVersion, app.Appversion, t.ObjectMeta.Annotations) | ||
objects[i] = t |
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.
@kadel the problem with this approach is that there is no guarantee we might not miss out on new object!
If tomorrow kedge starts supporting a new object and if we miss out on adding that here, we will have same problem as to calling addKeyValueToMap
in some fix*
method or in some create*
method.
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 there is a solution to this, if we have a default case where anything that we don't handle will come and we show it with big warning saying that this particular kind was not handled in this type switch!
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.
Having default is good practice and should be there! We should look at the solution where we don't even need type switch. Some simple unified way that will add labels to any runtime object regarding the type.
pkg/spec/resources.go
Outdated
if app.Appversion != "" { | ||
for i, object := range objects { | ||
switch t := object.(type) { | ||
case *ext_v1beta1.Ingress: |
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.
@piyush1594 all these cases can be clubbed together in one case
case *ext_v1beta1.Ingress, *os_route_v1.Route, *api_v1.Service, ..., *api_v1.ConfigMap:
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.
And since we are doing same thing in all cases, so we can add them together!
I think the right place to call this function where you are adding all these annotations/labels is in But another question that arises is that should we also be playing with |
Hmm, good question. Ideally yes. But it will require changing how we handle includeResources. |
Yes, that might be even better place. |
bbcfc9c
to
3115f46
Compare
Commits need to be merged / be one as well 👍 |
@@ -162,6 +162,10 @@ type BuildConfigSpecMod struct { | |||
|
|||
// ControllerFields are the common fields in every controller Kedge supports | |||
type ControllerFields struct { | |||
// Field to specify the version of application | |||
// +optional | |||
Appversion string `json:"appversion,omitempty"` |
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.
Hi @piyush1594. You can use intstr.IntOrString
from k8s.io/apimachinery/pkg/util/intstr
, check out #455 for inspiration ;-)
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.
Hey @kadel
I tried that function. It is working fine if input is string but if input is int, output is in quotes. And if nothing is in input, output is giving "0".
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.
And it gives error in case of float like appversion : 5.6
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.
@piyush1594 I think it is throwing "0" because it is converting the zero value of an int (which is 0) to a string.
One solution would be to make the type *intstr.IntOrString
(because zero value of a pointer is going to be nil
) and then check the value of AppVersion
is nil
or not. If it is nil
, this means that the user has not set the field.
However, I think that the internal implementation of instr.IntOrString
is a pointer anyway, so you can directly check if it is nil
or not, not sure about this though.
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.
@kadel for float values like 5.6
, I think we should have something like FloatOrString
, WDYT?
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.
@containscafeine Using pointer it resolved zero
value problem. Thanks
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.
@kadel for float values like 5.6, I think we should have something like FloatOrString, WDYT?
Hmm, good point. using IntOrString is not going to solve the problem when someone puts something like 5.6
(without quotes) :-(
lets check apimachinery what other types are there besides IntOrString , I bet that we will find something usefull
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.
Hmm, more and more I think about this. I would like to stop with this and just require appversion to be put in quotes as a regular 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.
We could have the same discussion for every field. This just doesn't make sense. Let's use string.
If the field is required to be a string then it has to be a string and for numbers, quotes are required.
If someone sets label the value to float 5.5
or 5
without quotes, Kubernetes will also fail (so does Kedge) and that is correct.
return nil, nil, errors.Wrap(err, "cannot set annotations") | ||
} | ||
} | ||
} |
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 needs to move to CoreOperations
right ?
Also you can put it in a function so, there won't be a need to have this code in between!
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.
@surajssd I tried it there but I was not able to get the value of appversion there, can you please suggest me some method to do that.
One I thought was that we can return the value of appversion along with all runtimeObjects
@@ -56,6 +56,9 @@ func (deployment *DeploymentSpecMod) Fix() error { | |||
|
|||
deployment.ControllerFields.ObjectMeta.Labels = addKeyValueToMap(appLabelKey, deployment.ControllerFields.Name, deployment.ControllerFields.ObjectMeta.Labels) | |||
|
|||
if deployment.ControllerFields.Appversion != "" { | |||
deployment.ControllerFields.ObjectMeta.Annotations = addKeyValueToMap(appVersion, deployment.ControllerFields.Appversion, deployment.ControllerFields.ObjectMeta.Annotations) | |||
} |
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.
If you do #454 (comment) this is not needed!
@@ -134,6 +137,8 @@ func (deployment *DeploymentSpecMod) createKubernetesController() (*ext_v1beta1. | |||
// TODO: merge with already existing labels and avoid duplication | |||
deploymentSpec.Template.ObjectMeta.Labels = deployment.Labels | |||
|
|||
deploymentSpec.Template.ObjectMeta.Annotations = deployment.Annotations |
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.
If you do #454 (comment) this is not needed!
deploymentConfig.ControllerFields.ObjectMeta.Annotations = addKeyValueToMap(appVersion, | ||
deploymentConfig.ControllerFields.Appversion, | ||
deploymentConfig.ControllerFields.ObjectMeta.Annotations) | ||
} |
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.
If you do #454 (comment) this is not needed!
pkg/spec/job.go
Outdated
|
||
if job.ControllerFields.Appversion != "" { | ||
job.ControllerFields.ObjectMeta.Annotations = addKeyValueToMap(appVersion, job.ControllerFields.Appversion, job.ControllerFields.ObjectMeta.Annotations) | ||
} |
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.
If you do #454 (comment) this is not needed!
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 can't be moved as that comment suggested, there is information about Kedge file structures in context of that function
We have to figure out this in general. This is a second global label/annotation (we already have This might require a bit of refactoring and handling artifacts generations in a better way |
@kadel yeah even I realize that, not sure right now what is the best way to do it! If you want we can extract the appVersion from the file, like we do for the controller, we do it for the appVersion. Unmarshal into a throw away struct only to extract the field value of appVersion, not sure if we wanna do that! This way the fucntion call can still remain in the CoreOperations. |
I would keep this as it is for now. At least all non-controller objects are done together. |
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.
LGTM, with caution of doing refactor soonish!
@surajssd what do you think about #454 (comment) do you agree? |
3115f46
to
c916a18
Compare
@kadel string is what I would like to see, removing all the complications which come with overloading of types. |
pkg/spec/types.go
Outdated
@@ -163,6 +163,10 @@ type BuildConfigSpecMod struct { | |||
|
|||
// ControllerFields are the common fields in every controller Kedge supports | |||
type ControllerFields struct { | |||
// Field to specify the version of application | |||
// +optional | |||
Appversion *AppVersionType `json:"appversion,omitempty"` |
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.
why not pointer to string directly? *string
?
pkg/spec/util.go
Outdated
//this will just convert whatever input given as appversion to string | ||
//and set the value of appversion so it will not give error at the time | ||
//of unmarshalling | ||
func (fs *AppVersionType) UnmarshalJSON(value []byte) 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.
we don't need to do this, it will be defined as nil even without this
pkg/spec/controller.go
Outdated
@@ -96,5 +99,44 @@ func CoreOperations(data []byte) ([]runtime.Object, []string, error) { | |||
return nil, nil, errors.Wrap(err, "unable to transform data") | |||
} | |||
|
|||
//Regex to find the location of appversion |
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.
If I understand it correctly this is basically manually parsing appversion from YAML. This is not nice.
Please leave it as it was before. It is better to set labels on multiple places than parsing it here like this.
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.
@kadel I did it because after that user can give input without quotes and also trailing zeroes and all the problem get solved.
I tried IntOrFloarOrString there I was facing trailing zeroes in float problem, otherwise we can use string and user have to give input in quotes
Lets just do it as a regular string as we do it in other fields. If we are going to do some hack around that for This is different case that We will fix the problem with setting labels in multiple places later without requiring hacks |
c916a18
to
86b4f7b
Compare
metadata(as key-pair in annotation) of deployment, job and deploymentConfig. It is optional and also empty value of `appversion` will not be added to metadata kedgeproject#407 Formatted code according to gofmt Added annotations to all the objects in resources.go, changed the type of appversion to string, declared a constant for appversion Formatted according to gofmt Added generalized method for all objects and removed type switch Formatted according to gofmt This will accpet input of appversion of any kind like integer or float or string without quotes Here using a special type to allow marshalling and git commit -am Fallback to previous implementation, using Type as string and adding annotations in different places and user have to give input in quotes in case of int or float
86b4f7b
to
b8a4279
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.
LGTM
Merging, as this is the version of this PR that was already approved by @surajssd |
This will add a new key
appversion
which will get reflected in themetadata(as key-pair in annotation) of deployment, job and
deploymentConfig. It is optional and also empty value of
appversion
will not be added to metadata #407