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 templating Openstack clusters as App CRs #635

Merged
merged 12 commits into from
Jan 20, 2022

Conversation

ljakimczuk
Copy link
Contributor

@ljakimczuk ljakimczuk commented Jan 17, 2022

Description

The kubectl gs template cluster --provider openstack is now able to output clusters as App CRs. It does that by running two additional commands underneath, one for templating the cluste-openstack app and another for templating the default-apps-openstack app.

In order to accomplished that, the below flags have been introduced:

  • --cluster-topology, set to false by default, when used cluster will be templated as App CR,
  • --cluster-user-configmap, the current command supports multiple flags for customizing cluster templating, though in the case of App CRs, the configuration must be provided in a form of values.yaml. We could try to translate the existing cluster flags to values.yaml before running the template app commands, and in fact I tried that at the beginning, though it quickly started to look messy and felt counterintuitive. Working with the values.yaml directly seems much more easier and flexible in configuration to the users, so I introduced this extra flag,
  • --default-apps-user-configmap, the same reasoning as above applies here,
  • --cluster-app-version, allows cluster app version selection,
  • --default-apps-app-version, allows default apps app version selection.

Examples

  1. $ kubectl gs template cluster --provider openstack --cluster-topology --organization giantswarm-2

Output:

---
apiVersion: application.giantswarm.io/v1alpha1
kind: App
metadata:
  labels:
    app-operator.giantswarm.io/version: 0.0.0
  name: ox0f8-cluster
  namespace: org-giantswarm-2
spec:
  catalog: control-plane-catalog
  config:
    configMap:
      name: ""
      namespace: ""
    secret:
      name: ""
      namespace: ""
  kubeConfig:
    context:
      name: ""
    inCluster: true
    secret:
      name: ""
      namespace: ""
  name: cluster-openstack
  namespace: org-giantswarm-2
  version: 0.1.0
---
apiVersion: application.giantswarm.io/v1alpha1
kind: App
metadata:
  labels:
    app-operator.giantswarm.io/version: 0.0.0
  name: ox0f8-default-apps
  namespace: org-giantswarm-2
spec:
  catalog: default
  config:
    configMap:
      name: ""
      namespace: ""
    secret:
      name: ""
      namespace: ""
  kubeConfig:
    context:
      name: ""
    inCluster: true
    secret:
      name: ""
      namespace: ""
  name: default-apps-openstack
  namespace: org-giantswarm-2
  version: 0.1.0
  1. $ kubectl gs template cluster --provider openstack --cluster-topology --organization giantswarm-2 --cluster-user-configmap /tmp/cm.yaml
---
apiVersion: v1
data:
  values: |
    clusterDescription: "My test cluster"
    organization: "giantswarm-2"
    cloudConfig: cloud-config
    cloudName: openstack

    kubernetesVersion: 1.20.9
    releaseVersion: 20.0.0-alpha1

    nodeClasses:
    - name: small
      machineFlavor: n1.small
      diskSize: 20

    controlPlane:
      class: default
      replicas: 3

    nodePools:
    - name: default
      class: default
      replicas: 3
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: zi95g-cluster-userconfig
  namespace: org-giantswarm-2
---
apiVersion: application.giantswarm.io/v1alpha1
kind: App
metadata:
  labels:
    app-operator.giantswarm.io/version: 0.0.0
  name: zi95g-cluster
  namespace: org-giantswarm-2
spec:
  catalog: control-plane-catalog
  config:
    configMap:
      name: ""
      namespace: ""
    secret:
      name: ""
      namespace: ""
  kubeConfig:
    context:
      name: ""
    inCluster: true
    secret:
      name: ""
      namespace: ""
  name: cluster-openstack
  namespace: org-giantswarm-2
  userConfig:
    configMap:
      name: zi95g-cluster-userconfig
      namespace: org-giantswarm-2
  version: 0.1.0
---
apiVersion: application.giantswarm.io/v1alpha1
kind: App
metadata:
  labels:
    app-operator.giantswarm.io/version: 0.0.0
  name: zi95g-default-apps
  namespace: org-giantswarm-2
spec:
  catalog: default
  config:
    configMap:
      name: ""
      namespace: ""
    secret:
      name: ""
      namespace: ""
  kubeConfig:
    context:
      name: ""
    inCluster: true
    secret:
      name: ""
      namespace: ""
  name: default-apps-openstack
  namespace: org-giantswarm-2
  version: 0.1.0
  1. $ kubectl gs template cluster --provider openstack --organization giantswarm-2 --release 20.0.0-alpha1 --node-machine-flavor=n1.small (some output has been cut for brevity)
---
apiVersion: cluster.x-k8s.io/v1alpha4
kind: Cluster
metadata:
  annotations:
    cluster.giantswarm.io/description: ""
  labels:
    cluster.x-k8s.io/cluster-name: kz4j9
    giantswarm.io/cluster: kz4j9
    giantswarm.io/organization: giantswarm-2
    release.giantswarm.io/version: 20.0.0-alpha1
  name: kz4j9
  namespace: org-giantswarm-2
spec:
  controlPlaneEndpoint:
    host: ""
    port: 0
  controlPlaneRef:
    apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
    kind: KubeadmControlPlane
    name: kz4j9
    namespace: org-giantswarm-2
  infrastructureRef:
    apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
    kind: OpenStackCluster
    name: kz4j9
    namespace: org-giantswarm-2
status:
  infrastructureReady: false
---
...
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: OpenStackMachineTemplate
metadata:
  labels:
    cluster.x-k8s.io/cluster-name: kz4j9
    giantswarm.io/cluster: kz4j9
    giantswarm.io/organization: giantswarm-2
    release.giantswarm.io/version: 20.0.0-alpha1
  name: kz4j9
  namespace: org-giantswarm-2
spec:
  template:
    spec:
      cloudName: openstack
      flavor: n1.small
      identityRef:
        kind: Secret
        name: cloud-config
      image: ubuntu-2004-kube-v1.20.9
      rootVolume: {}

cmd/template/app/runner.go Outdated Show resolved Hide resolved
cmd/template/cluster/flag.go Outdated Show resolved Hide resolved
cmd/template/cluster/flag.go Outdated Show resolved Hide resolved
cmd/template/cluster/flag.go Outdated Show resolved Hide resolved
cmd/template/cluster/flag.go Outdated Show resolved Hide resolved
cmd/template/cluster/provider/capo.go Outdated Show resolved Hide resolved
cmd/template/cluster/provider/common.go Outdated Show resolved Hide resolved
cmd/template/cluster/runner.go Outdated Show resolved Hide resolved
cmd/template/cluster/provider/capo.go Show resolved Hide resolved
cmd/template/cluster/provider/capo.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rossf7 rossf7 left a comment

Choose a reason for hiding this comment

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

@ljakimczuk This is looking good but CI isn't happy. Can you check and appease the Circle gods? :)

@ljakimczuk
Copy link
Contributor Author

This is looking good but CI isn't happy. Can you check and appease the Circle gods? :)

Sure!

@ljakimczuk ljakimczuk requested a review from a team January 18, 2022 14:49
@ljakimczuk ljakimczuk changed the title [WIP] Templating Cluster as App CRs Templating Openstack Clusters as App CRs Jan 18, 2022
@ljakimczuk ljakimczuk changed the title Templating Openstack Clusters as App CRs Support templating Openstack clusters as App CRs Jan 18, 2022
Copy link
Contributor

@rossf7 rossf7 left a comment

Choose a reason for hiding this comment

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

Nice<3 this is looking good. Just some final nits on ordering.

We should get a review from Sig UX before merging but we can start with a review from the team.

We'll also need a docs PR 📚 https://docs.giantswarm.io/ui-api/kubectl-gs/template-cluster/

cmd/template/cluster/flag.go Show resolved Hide resolved
@ljakimczuk ljakimczuk marked this pull request as ready for review January 18, 2022 15:50
@ljakimczuk ljakimczuk requested a review from a team January 18, 2022 15:50
@ljakimczuk
Copy link
Contributor Author

ljakimczuk commented Jan 18, 2022

We'll also need a docs PR.

@rossf7 I remember about that, but let's maybe wait for that until we get more reviews, just in case we have more changes coming in. WDYT?

@ljakimczuk ljakimczuk requested a review from a team January 18, 2022 15:56
@rossf7
Copy link
Contributor

rossf7 commented Jan 18, 2022

maybe wait for that until we get more reviews, just in case we have more changes coming in. WDYT?

@ljakimczuk Yes that's fine 👍

@rossf7 rossf7 requested a review from tfussell January 18, 2022 15:59
Copy link
Contributor

@anvddriesch anvddriesch left a comment

Choose a reason for hiding this comment

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

Cool stuff!
Please list all the changes to the CHANGELOG.

cmd/template/cluster/flag.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rossf7 rossf7 left a comment

Choose a reason for hiding this comment

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

LGTM when @anvddriesch and team 🌈 are happy

Agree it makes sense to hide the openstack flags for now.

@ljakimczuk
Copy link
Contributor Author

@rossf7 @anvddriesch @tfussell done, flags are now hidden and the changlog entry is there, let me know if I should make it more detailed.

Copy link
Contributor

@anvddriesch anvddriesch left a comment

Choose a reason for hiding this comment

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

LGTM

@kopiczko
Copy link
Member

Do we need to keep raw at all?

@ljakimczuk
Copy link
Contributor Author

@kopiczko not necessarily, it seemed more consistent to me to have this type, but it would work just as good without it. We can get rid of it or change this flag to something not suggesting multiple types, for example, --as-app or similar

@kopiczko
Copy link
Member

can get rid of it or change this flag to something not suggesting multiple types, for example, --as-app or similar

I thought we could replace existing templates and ditch them altogether.

@ljakimczuk
Copy link
Contributor Author

I believe the original idea was to support both templates types, at least for some time since some users may be interested in templating raw resources, but maybe I got it wrong. @rossf7 WDYT?

@kopiczko
Copy link
Member

Asked @cornelius-keller

@cornelius-keller
Copy link

I think currently it does not hurt and gives the customer the opportunity to create the clusters with the old method still, which might be useful in case there are problems with the new ones and we need to compare them to see what is different.

In the long run I agree with @kopiczko and it should disappear or be renamed, especially because customers can expect that the raw method templates the same cluster as the app method only that it is the raw template and not wrapped into an app.

Maybe it will be useful to provide an option to get a raw template that is the same as included in the app, but that is a different story.

LGTM

@kopiczko
Copy link
Member

It would be nice to at least generate raw templates using helm template to make sure they are always on par.

@ljakimczuk
Copy link
Contributor Author

It would be nice to at least generate raw templates using helm template to make sure they are always on par.

This may be misleading for those relying on the "old" version for the migration time being and as far as I understood that's indeed the case. But since app is mostly about adding ClusterTopology, @tfussell suggested we could change the flag to --cluster-topology [true|false], @tfussell would you like to add something to that?

@marians
Copy link
Member

marians commented Jan 19, 2022

Haven't read through the entire discussion.

One minor thing that stands out to me is the duplication of the term template in the flag --template-type. If we need that flag, could it simply be --type ?

@ljakimczuk
Copy link
Contributor Author

One minor thing that stands out to me is the duplication of the term template in the flag --template-type. If we need that flag, could it simply be --type

I duplicated term template to emphasize the fact it's about the template type. I was afraid purpose of the --type alone may be vague having all the providers and different resources generated.

@tfussell has already proposed to change this flag to something else, namely --cluster-topology [true|false], that more closely describe the purpose of having an app for cluster, what do you think @marians ?

When we have an agreement I will push the changes.

@marians
Copy link
Member

marians commented Jan 19, 2022

With a boolean flag, the default (when the flag is not used) should always be false. So --cluster-topology false would be the default. I'd like to make sure that the default makes sense.

What sort of output will that (--cluster-topology false) generate then, and what will --cluster-topology or --cluster-topology true generate instead?

@ljakimczuk
Copy link
Contributor Author

@marians The --cluster-topology false in this scenario would behave the same way the --template-type raw (or lack of it) behaves. The cluster-topology true would behave the same way the --template-type app behaves right now.

@ljakimczuk ljakimczuk requested a review from a team January 20, 2022 13:56
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.

None yet

8 participants