Skip to content

kev-458 remove label validation#482

Merged
mangas merged 5 commits intolabels-to-extensionfrom
kev-458-remove-label-validation
Apr 27, 2021
Merged

kev-458 remove label validation#482
mangas merged 5 commits intolabels-to-extensionfrom
kev-458-remove-label-validation

Conversation

@mangas
Copy link
Contributor

@mangas mangas commented Apr 23, 2021

No description provided.

@mangas mangas marked this pull request as draft April 23, 2021 10:56
@mangas mangas marked this pull request as ready for review April 23, 2021 15:38
@ezodude ezodude requested review from ezodude and marcinc April 26, 2021 04:59
Copy link
Contributor

@ezodude ezodude left a comment

Choose a reason for hiding this comment

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

Left some questions/comments.

All in all a great step forward.

func assertLog(level logrus.Level, message string, fields map[string]string) {
Expect(hook.LastEntry().Level).To(Equal(level))
Expect(hook.LastEntry().Message).To(Equal(message))
Expect(cmp.Diff(hook.LastEntry().Message, message)).To(BeEmpty())
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious on why you had to diff here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I was investigating I couldn't see the whole sentence, just the small difference and it is not useful. This will basically show the 2 sentences in full so it';s easier to understand what changed

}

return config.DefaultReplicaNumber
return int32(p.K8SConfig.Workload.Replicas)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay! 🥳

Copy link
Member

@marcinc marcinc Apr 26, 2021

Choose a reason for hiding this comment

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

That's great, but should probably guard against values passed as strings too? As it stands it'll fail to extract replicas from the following config:

x-k8s:
  workload:
    replicas: "10"

Would be good to either support that also, OR handle the error if value is not as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will not pass validation because it won't be the right type. At this point we're operating on top of K8SConfiguration which is a struct with defined types. So passing replicas: "10" would result in either a parsing error or a validation error. In either case it is detected before it gets to project_service


Describe("enabled", func() {

When("component toggle label is set to Truthy value", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may have to be reworded as we were previously working with string conversion.

Copy link
Member

Choose a reason for hiding this comment

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

I guess that's still OK, as the value you can pass in the struct can be anything so good to ensure it's truthy. But since we switched from enabled to the reverse of that some text will need to change for sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

labels = composego.Labels{
config.LabelWorkloadType: projectWorkloadType,
}
JustBeforeEach(func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

No sure why we started using JustBeforeEach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because we need to change the extensions and in this case the tests needs to override the creation of the project service since it can't be updated easily

Copy link
Contributor

Choose a reason for hiding this comment

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

I see.

Personally, to keep spec files simple, I try to only use just one JustBeforeEach for the entire spec file. This keeps things readable and easier to understand.

Do you think multiple JustBeforeEach statements are code small signalling that we need to split this test file into smaller test files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I think so for sure, don't think this is the right time to do it though because of the big refactor in progress but I will definitely add it to the list

BeforeEach(func() {
labels = composego.Labels{
config.LabelWorkloadRestartPolicy: policy,
JustBeforeEach(func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

No sure why we started using JustBeforeEach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because we need to change the extensions and in this case the tests needs to override the creation of the project service since it can't be updated easily

Copy link
Contributor

Choose a reason for hiding this comment

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

func newServiceConfig(s composego.ServiceConfig) (ServiceConfig, error) {
config := ServiceConfig{Name: s.Name, Labels: s.Labels, Environment: s.Environment, Extensions: s.Extensions}
return config, config.validate()
return config, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to return an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer keeping it just because updating the api requires more changes. I think this kind of cleanup should be done afterwards to minimize conflicts with master

Copy link
Contributor

Choose a reason for hiding this comment

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

cool.

Copy link
Member

@marcinc marcinc left a comment

Choose a reason for hiding this comment

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

A few comments

default:
return RestartPolicyAlways
if svc.Deploy != nil && svc.Deploy.RestartPolicy != nil {
policy = svc.Deploy.RestartPolicy.Condition
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't be returning a literal value from compose here. Previously we were mapping that value to the expected restart policy but this code was removed above.. As it stands this func will be returning mixed values.

Copy link
Member

Choose a reason for hiding this comment

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

Unless this func is meant to return the literal value extracted from compose (if present)? In which case it'd be the extracted value or an empty string, so no priming policy with RestartPolicyAlways needed. Does the switch statement need to be moved somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bit where we're moving validation to a different place. The default value used to be handled by project_service but now that doesn't make much sense since this configuration should be responsible for that part. The code as it preserves the functionality since the tests are still covering the same behaviour

}

return config.DefaultReplicaNumber
return int32(p.K8SConfig.Workload.Replicas)
Copy link
Member

@marcinc marcinc Apr 26, 2021

Choose a reason for hiding this comment

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

That's great, but should probably guard against values passed as strings too? As it stands it'll fail to extract replicas from the following config:

x-k8s:
  workload:
    replicas: "10"

Would be good to either support that also, OR handle the error if value is not as expected.

workloadType)
}

return workloadType
Copy link
Member

Choose a reason for hiding this comment

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

I guess no need to change the return value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted this. to use workloadType, this was left because of copy paste. I brought back the logging but forgot to change this last return

})

When("component toggle label is set to any string value not representing a boolean value (one of: 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.)", func() {
When("component toggle extension to set false value", func() {
Copy link
Member

Choose a reason for hiding this comment

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

The configuration map may contain values that aren't bool.. eg. "true" , 1, TRUE. It'd make sense to respect and handle those "truthy" values I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

again, we no longer look at maps, we only look at the configuration struct which is type safe so if those values are set wrong they will be either caught by marshalling or validation, this is not the place to check for any of it.

})

It("will use a replica number as specified in deploy block", func() {
Expect(projectService.Deploy.Replicas).NotTo(BeNil())
Copy link
Member

Choose a reason for hiding this comment

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

Maybe best to assert that the number of replicas is as expected here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check is just to ensure that the value set in BeforeEach is being picked up, the following assertion verifies the value so I don't think we need to make this more specific IMO, but if you want I can change it

})

It("warns the user and defaults restart policy to `Always`", func() {
Expect(projectService.K8SConfig.Workload.RestartPolicy).To(Equal(policy))
Copy link
Member

Choose a reason for hiding this comment

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

Are we expecting workload RestartPolicy defined in x-k8s as "unless-stopped" here i.e. compose notation? or one of the values we defined for it in label based configuration? See: https://github.com/appvia/kev/blob/master/docs/reference/config-params.md#kevworkloadrestart-policy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k8s should hold whatever is inferred from compose and then merged with extensions content. So both cases can happen.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I guess we just need to ensure that what we derive from docker compose is translated into values we want the end user to see/tweak. Currently we let the user to adjust configuration based on the config params we defined - see link above.

And these are the only values we should be populating in the projectService.K8SConfig.Workload.RestartPolicy.

The spec above expects that the value of projectService.K8SConfig.Workload.RestartPolicy is unless-stopped which I don't think is correct as it should be one of allowed values: Always, OnFailure, Never.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so if I understand correctly, you're proposing we move this to the config.K8SCfgFromCompose?

ReadinessProbe: config.DefaultReadinessProbe(),
Type: config.DefaultWorkload,
Replicas: config.DefaultReplicaNumber,
RestartPolicy: "always",
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 config.DefaultRestartPolicy I reckon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

config.DefaultRestartPolicy is "Always" and the specific code from project_service was setting "always" so i left it as it was to avoid adding to the changes. It's definitely something that can be improved later

"restart-policy": policy,
}, "Restart policy 'unless-stopped' is not supported, converting it to 'always'")

policy = "always"
Copy link
Member

Choose a reason for hiding this comment

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

OK, this function now returns what has been defined in the docker compose around restart policy, however, we prime the value of policy in the first statement to be config.RestartPolicyAlways which is a Kev config parameter value. Perhaps change it to literal string "always" instead?

Copy link
Contributor

@ezodude ezodude left a comment

Choose a reason for hiding this comment

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

👍 Looks good - I'll defer to @marcinc for the final approval (he understands this bit of the code more than I do 😉).

Copy link
Member

@marcinc marcinc left a comment

Choose a reason for hiding this comment

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

LG. We can address outstanding elements in the follow up PRs.

@mangas mangas merged commit d30ea49 into labels-to-extension Apr 27, 2021
@mangas mangas deleted the kev-458-remove-label-validation branch April 27, 2021 12:42
ezodude pushed a commit that referenced this pull request May 27, 2021
* kev-458 remove label validation
ezodude pushed a commit that referenced this pull request Jun 4, 2021
* kev-458 remove label validation
ezodude added a commit that referenced this pull request Jun 4, 2021
* add extension support (#432)

* add extension support

* add extensions to init (#439)

* kev-449 overlay validation (#451)

* kev-458 Render probe info from extensions (#459)

* Latest from master.

* kev-458 remove label validation (#482)

* kev-458 remove label validation

* Kev 458 cleanup moved extensions (#483)

* kev-458 cleanup moved extensions

* remove unused code

* kev-458 move imagepull labels (#498)

* kev-458 move resource (#499)

* kev-458 move cpu (#500)

* Bug fix - can now use correct workload type during init and render. (#504)

* Extract volume settings into a volumes K8s extension (#502)

* Enable volumes reconciliation for extensions. (#506)

* Render volumes using extension settings (#508)

* Remove volume labels use (#509)

* Moved the autoscale labels to extensions. (#514)

* Move the pod-security labels to extensions. (#516)

* Move the rolling update max surge and service account name to extensions. (#519)

* Move the service labels to extensions (#521)

* Remove services labels use. (#525)

* Turn Restart Policy string value sets into enums (#533)

* Turn Workload Type and Service Type value sets into enums (#534)

* Minify Extensions (#536)

* Set correct livenessProbe success threshold (#548)

* Update the documentation to use extensions instead of labels. (#547)

* Handle ingress with kubernetes cluster defaults (#552)
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