Skip to content

[Cluster Stacks] Automate creation of Cluster Stack release assets using Zuul  #727

Open

Description

@jschoone

Things to automate

Activity

  1. added
    enhancement
    Ops
    needs refinement
    Container
    on Nov 7, 2024
  2. jschoone commented on Nov 8, 2024

    @jschoone
    Author

    Notes about all the stuff

    Requirements:

    • git
    • go
    • make
    • PyYAML
    • helm

    Build and publish Cluster Stacks

    Basic workflow to create assets from Cluster Stack defintion

    git clone https://github.com/SovereignCloudStack/cluster-stacks
    git clone https://github.com/SovereignCloudStack/csctl
    git clone https://github.com/SovereignCloudStack/csctl-plugin-openstack
    cd csctl
    make build
    cp csctl /usr/local/bin
    cd ../csctl-plugin-openstack
    make build
    cp csctl-openstack /usr/local/bin
    cd ../cluster-stacks
    ./hack/generate_version.py --build # works only for Cluster Stack openstack-scs
    csctl create -m hash providers/openstack/out/1-29/ # useless in ci because assets are only available locally

    Needed secrets:
    OCI_REGISTRY
    OCI_REPOSITORY
    OCI_USERNAME
    OCI_PASSWORD
    or
    OCI_ACCESS_TOKEN

    KUBECONFIG

    Workflow to push assets to OCI registry

    # export OCI_ variables
    cd cluster-stacks
    csctl create -m hash --publish --remote oci providers/openstack/out/1-29/
    

    in our example we got version openstack-scs-1-29-v0-sha-ihtybxi
    which is available in .releases and in the $OCI_REPOSITORY

    Thoughts:
    When generating cluster stacks with generate_version.py, versions should always be in providers/openstack/scs
    Example for 1.29:

    1. generate versions
    2. replace generated folder providers/openstack/scs with providers/openstack/out/1-29
    3. push to branch chore/update-1.29
    4. create PR against release-1.29

    Automatically check for new versions

    We depend on various versions

    Test in Cluster (probably out of scope here)

    Results in Cluster Stack object:

    apiVersion: clusterstack.x-k8s.io/v1alpha1
    kind: ClusterStack
    metadata:
      name: openstack-scs-129
    spec:
      autoSubscribe: false
      channel: stable
      kubernetesVersion: "1.29"
      name: scs
      noProvider: false
      provider: openstack
      providerRef:
        apiVersion: infrastructure.clusterstack.x-k8s.io/v1alpha1
        kind: OpenStackClusterStackReleaseTemplate
        name: cspotemplate
      versions:
        - v0-sha.ihtybxi
    
    ---
    apiVersion: cluster.x-k8s.io/v1beta1
    kind: Cluster
    metadata:
      name: cs-cluster
      labels:
        managed-secret: cloud-config
    spec:
      topology:
        class: openstack-scs-1-29-v0-sha.ihtybxi
        controlPlane:
          replicas: 1
        version: v1.29.10
        workers:
          machineDeployments:
            - class: default-worker
              name: md-0
              replicas: 1
    
  3. self-assigned this
    on Nov 11, 2024
  4. jschoone commented on Nov 11, 2024

    @jschoone
    Author

    Hi @o-otte,
    only needed for the last part: as mentioned on Friday I used a script for automatically creating the ClusterStack object I didn't checked in somewhere because it's not very stable, but was enough for my tests.
    But maybe it can be used for inspiration or something :D
    See here:

    #!/bin/bash
    
    # Given directory name
    #directory_name=".release/openstack-scs-1-27-v0-sha-zciidfn"
    directory_name=$1
    
    # Extract parts from the directory name
    IFS='/' read -ra PARTS <<<"$directory_name"
    IFS='-' read -ra PARTS <<<"${PARTS[1]}"
    
    provider="${PARTS[0]}"
    name="${PARTS[1]}"
    kubernetes_major_version="${PARTS[2]}"
    kubernetes_minor_version="${PARTS[3]}"
    version="${PARTS[4]}-${PARTS[5]}.${PARTS[6]}"
    channel="custom"
    
    if [[ -z ${PARTS[6]} ]]; then
      version="${PARTS[4]}"
      channel="stable"
    fi
    
    # Create the YAML structure
    clusterstack_yaml=$(
      cat <<EOF
    ---
    apiVersion: clusterstack.x-k8s.io/v1alpha1
    kind: ClusterStack
    metadata:
      name: ${provider}-${name}-${kubernetes_major_version}-${kubernetes_minor_version}
    spec:
      provider: ${provider}
      name: ${name}
      kubernetesVersion: "${kubernetes_major_version}.${kubernetes_minor_version}"
      channel: ${channel}
      autoSubscribe: false
      providerRef:
        apiVersion: infrastructure.clusterstack.x-k8s.io/v1alpha1
        kind: OpenStackClusterStackReleaseTemplate
        name: cspotemplate
      versions:
      - ${version}
    EOF
    )
    
    # Print the YAML content
    echo "$clusterstack_yaml"
  5. okautz commented on Nov 11, 2024

    @okautz

    Thanks!

    I've started to create a justfile to automate the first step, including building csctl and the `csctl openstack plugin to enable a local user and later the CI to use it as discussed.

    This will be the current working PR: SovereignCloudStack/cluster-stacks#184

  6. okautz commented on Nov 14, 2024

    @okautz

    Workflow automation can now create all assets locally with one command. All commands are idempotent as long as there are no changes in the versions.yaml file.

    Will continue on Monday with the upload to the registry. OCI_ variables will be fetched from a just.env file. Afterwards, this will be integrated with Zuul.

  7. okautz commented on Nov 29, 2024

    @okautz

    @jschoone As discussed, I've added some final changes to the justfile, including draft recipes for creating ClusterStack and Cluster ressources as well as a test if the clusterstack manifest could be applied. This needs to get fleshed out for real world use.

    I also created two playbooks to:

    1. Upload Assets to the OCI registry (hashed more for PRs, stable more for post-merge Runs)
    2. Create chore branches and PRs

    The last commit also includes Zuul Job definitions that use those playbooks.

    The following is left to do:

    • A (new) Zuul base job is needed that does the credentials handling with Vault for the SCS Registry as well as for a GitHub Token needed for pushing to the feature branches as well as opening the PRs.
    • Attaching of Zuul Jobs to Zuul Pipelines
    • Setting up Zuul to recognize PRs against the release branches.
  8. removed their assignment
    on Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ContainerOpsenhancementneeds refinement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions