Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Validation support for strings, arrays, numbers #329

Merged
merged 37 commits into from
Dec 18, 2020
Merged

Conversation

Porges
Copy link
Member

@Porges Porges commented Nov 18, 2020

Ok, this got a bit bigger than expected:

  • Add ValidatedType which adds support for validations.
  • Handle specially the ^.*/default$ validation used by Storage for names; disable AzureName when detected.
    • To do in future PR: make this more general.
  • Add SetAzureName function instead of writing the “setter” code inline in the from-ARM conversion, which simplifies things somewhat.
  • Simplify PropertyDefinition by removing general validation support; properties only have Required as a validation.
  • Add a Defaulter webhook to copy Name into AzureName (when required), this has a marker comment for controller-gen which outputs the webhook configuration files.
  • Set up webhooks for integration tests.

Base automatically changed from the-resource-named-default to master November 19, 2020 04:11
@Porges Porges force-pushed the validation-support branch 2 times, most recently from 440ceef to ff50ac7 Compare November 19, 2020 04:14
- if [ -d "./config/crd/bases" ]; then find "./config/crd/bases" -type f -delete; fi
- controller-gen object:headerFile=../boilerplate.go.txt paths="./..." || true
Copy link
Member Author

@Porges Porges Nov 19, 2020

Choose a reason for hiding this comment

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

TO FIX: controller-gen emitting bad code

@Porges Porges force-pushed the validation-support branch 2 times, most recently from 2e50efe to c01d898 Compare November 22, 2020 22:35
@Porges Porges changed the base branch from master to dst November 22, 2020 22:36
@@ -123,10 +122,7 @@ func StorageAccount_BlobServices_CRUD(t *testing.T, testContext testcommon.KubeP
g := NewGomegaWithT(t)

blobService := &storage.StorageAccountsBlobService{
ObjectMeta: ctrl.ObjectMeta{
Name: "default", // MUST be 'default'
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the thing I’ve been working towards 😀

Copy link
Member Author

Choose a reason for hiding this comment

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

(I know @babbageclunk likes stuff like this 😉)

Copy link
Member

Choose a reason for hiding this comment

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

It's like when they say the title of the movie in the movie.

@Porges Porges force-pushed the validation-support branch 2 times, most recently from 7902a4a to b341b50 Compare November 23, 2020 04:05
Base automatically changed from dst to master November 23, 2020 19:47
@Porges Porges force-pushed the validation-support branch from b341b50 to b56a371 Compare November 23, 2020 19:49
Taskfile.yml Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Nov 23, 2020

Coverage Status

Coverage increased (+13.02%) to 65.353% when pulling 34dbb99 on validation-support into 1d9651a on master.

Taskfile.yml Outdated Show resolved Hide resolved
@Porges Porges force-pushed the validation-support branch from 16d020a to 9dcbb87 Compare November 24, 2020 20:05
@Porges Porges force-pushed the validation-support branch from 9dcbb87 to ce697e2 Compare November 24, 2020 20:35
dir: "{{.CONTROLLER_ROOT}}"
deps: [generate-crds]
cmds:
# the webhook configuration file, as it stands, is too big to load into k8s 😊
Copy link
Member

Choose a reason for hiding this comment

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

Should we open an issue with kubebuilder on this topic? Presumably the issue is that the yaml file is too big but if it were split up it'd be ok?

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe there already is one? Link it here if so?

Copy link
Member Author

@Porges Porges Dec 1, 2020

Choose a reason for hiding this comment

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

It might actually be small enough now; part of the earlier problem was webhook definitions were being generated for the storage types.

Copy link
Member Author

Choose a reason for hiding this comment

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

A few other thoughts:

  • Yes, I think controller-gen should generate multiple files
  • We should be able to generate fewer webhooks that apply to more types.

Taskfile.yml Outdated Show resolved Hide resolved
hack/generated/pkg/genruntime/base_types.go Show resolved Hide resolved
@@ -22,7 +22,7 @@ type PropertyDefinition struct {
propertyName PropertyName
propertyType Type
description string
validations []Validation
isRequired bool
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this about the required validation?

Why have this here then?

Copy link
Member

Choose a reason for hiding this comment

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

Oh it's about the validation and the Optional-ness of the type, ok.

Copy link
Member Author

Choose a reason for hiding this comment

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

the requiredness is a property of the property, not of the type of the property (this is all a bit conflated by us because we tie this to optionalness via MakeRequired/MakeOptional)

hack/generator/pkg/astmodel/property_definition_test.go Outdated Show resolved Hide resolved
@Porges Porges self-assigned this Dec 3, 2020
Copy link
Member

@theunrepentantgeek theunrepentantgeek left a comment

Choose a reason for hiding this comment

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

Some minor feedback, nothing too material.

@Porges Porges merged commit 6842fcf into master Dec 18, 2020
@Porges Porges deleted the validation-support branch December 18, 2020 00:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants