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

Support for conditionally enabling of alpha-level CRDs #462

Merged
merged 30 commits into from
Aug 1, 2023

Conversation

dmitri-d
Copy link
Contributor

@dmitri-d dmitri-d commented Jul 15, 2023

If CRD doesn't contain any alpha version of resources, produced CRD templates are almost identical to CRD manifests in crds/ directory.

A given alpha-version CRD can be enabled by adding its GVK to experimental.api helm chart variable.
If there's a single alpha version resource in a CRD, the whole thing is rendered conditionally:

{{- if has "waypointlifecyclemanagers.admin.gloo.solo.io/v2alpha1" $.Values.enabledExperimentalApi }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    crd.solo.io/version: 2.4.0
  labels:
    app: gloo-mesh-apis
    app.kubernetes.io/name: gloo-mesh-apis
  name: waypointlifecyclemanagers.admin.gloo.solo.io
spec:
  group: admin.gloo.solo.io
  names:
    categories:
    - solo-io
    kind: WaypointLifecycleManager
    listKind: WaypointLifecycleManagerList
    plural: waypointlifecyclemanagers
    singular: waypointlifecyclemanager
  scope: Namespaced
  versions:
  - name: v2alpha1
    schema:
      openAPIV3Schema:
        properties:
          spec:
...
    served: true
    storage: true
    subresources:
      status: {}
{{- end  }}

If a CRD contains multiple versions and one of them is alpha, then only that version can be rendered conditionally:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    crd.solo.io/version: 2.4.0
  labels:
    app: gloo-mesh-apis
    app.kubernetes.io/name: gloo-mesh-apis
  name: workspaces.admin.gloo.solo.io
spec:
  group: admin.gloo.solo.io
  names:
    categories:
    - solo-io
    kind: Workspace
    listKind: WorkspaceList
    plural: workspaces
    shortNames:
    - ws
    singular: workspace
  scope: Namespaced
  versions:
  - name: v2
    schema:
      openAPIV3Schema:
...
    served: true
    storage: true
    subresources:
      status: {}
  {{- if has "workspaces.admin.gloo.solo.io/v2alpha1" $.Values.enabledExperimentalApi }}
  - name: v2alpha1
    schema:
      openAPIV3Schema:
        properties:
          spec:
...
    served: true
    storage: false
    subresources:
      status: {}
  {{- end }}
---

This partially resolves https://github.com/solo-io/gloo-mesh-enterprise/issues/9019
BOT NOTES:
resolves https://github.com/solo-io/gloo-mesh-enterprise/issues/9019

Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
@dmitri-d dmitri-d marked this pull request as draft July 15, 2023 03:39
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
@dmitri-d dmitri-d marked this pull request as ready for review July 27, 2023 03:49
@solo-changelog-bot
Copy link

Issues linked to changelog:
https://github.com/solo-io/gloo-mesh-enterprise/issues/9019

@dmitri-d dmitri-d requested a review from Sodman July 27, 2023 04:09
@dmitri-d
Copy link
Contributor Author

Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
@dmitri-d dmitri-d self-assigned this Jul 27, 2023
…hered groups

Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Copy link
Contributor

@josh-pritchard josh-pritchard left a comment

Choose a reason for hiding this comment

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

Looks really good, a few small nits but this is exactly what we needed. Nice work.

codegen/kuberesource/crd.go Show resolved Hide resolved
codegen/render/manifests_renderer.go Outdated Show resolved Hide resolved
Comment on lines 22 to 26
[[- if and (and (gt (len $crd.Spec.Versions) 1) (string_contains $version.Name "alpha")) (should_not_skip $crd.Spec.Group $version.Name $.ShouldSkip) ]]
{{- end }}
[[- end ]]
[[- end ]]
[[- if and (and (lt (len $crd.Spec.Versions) 2) (string_contains (index $crd.Spec.Versions 0).Name "alpha")) (should_not_skip $crd.Spec.Group (index $crd.Spec.Versions 0).Name $.ShouldSkip) ]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these just to make sure new-lines are created when needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what exactly you are referring to. If it's the conditional on the line above, it's to conditionally render {{- end }} that corresponds to the conditional here: https://github.com/solo-io/skv2/pull/462/files/acf693e11fd37032d1e9813a85d5e6888a1c0a4d#diff-033b9d4512e2683aff9f19928ec94eaaa06e46cbfcede987461da2079459436dR3

Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
codegen/cmd.go Outdated
}

manifests, err := render.RenderManifests(c.AppName, c.ManifestRoot, c.ProtoDir, protoOpts, groupOptions, grp)
manifests, err := render.RenderManifests(c.AppName, c.ManifestRoot, c.ProtoDir, protoOpts, groupOptions, grps)
Copy link
Member

Choose a reason for hiding this comment

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

we sohuld just move RenderManifests out rather than changing the whole function signature for this one line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly sure what you mean. RenderManifests needs all groups now, as it combines multiple versions of the same group into one manifest (and multiple versions of the same resource into a single crd).

Copy link
Member

@Sodman Sodman left a comment

Choose a reason for hiding this comment

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

Overall LGTM, couple questions and nits.

codegen/cmd.go Outdated Show resolved Hide resolved
resource,
group.OpenApiSchemas,
)
groups []*model.Group,
Copy link
Member

Choose a reason for hiding this comment

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

Implementation looks fine to me, but this function is getting a little complex, we might want to break into a couple smaller simpler funcs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cleaned it up a little bit.

codegen/kuberesource/crd.go Outdated Show resolved Hide resolved
codegen/model/resource.go Outdated Show resolved Hide resolved
if err != nil {
return OutFile{}, err
}
return files[0], nil
Copy link
Member

Choose a reason for hiding this comment

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

Files always len 1? Should we check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we only give defaultManifestRenderer.renderCoreTemplates one template to render; if there's an error it will return before this line. So, yes, if it got here, there is one item in []OutFile. I'll add a comment.

labels:
app: ""
app.kubernetes.io/name: ""
name: paints.things.test.io
name: clusterresources.things.test.io
Copy link
Member

Choose a reason for hiding this comment

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

Did these changes result in the ordering of CRDs change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. There are a few interim maps: for grouping of groups, which also affected ordering of versions in CRDs. To make those stable, I added sorting in both places:

Comment on lines +280 to +281
renderer.left = "[["
renderer.right = "]]"
Copy link
Member

Choose a reason for hiding this comment

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

To confirm, this is because the template we are rendering will itself contain template syntax? (i.e. codegen/templates/manifests/crd.yamltmpl)?

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. [[ and ]] are for the template code that executes during code-generation pass, while {{ and }} for when template is rendered by helm. We do the same in chart_renderer (which is where I got the idea): https://github.com/solo-io/skv2/blob/master/codegen/render/chart_renderer.go#L47

Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
dmitri-d and others added 9 commits July 28, 2023 13:29
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
…bled alpha API

Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
Signed-off-by: Dmitri Dolguikh <dmitri@appliedlogic.ca>
@soloio-bulldozer soloio-bulldozer bot merged commit ac641d9 into master Aug 1, 2023
2 checks passed
@soloio-bulldozer soloio-bulldozer bot deleted the dmitrid-crd-install branch August 1, 2023 13:34
chunter0 added a commit that referenced this pull request Aug 7, 2023
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.

5 participants