Skip to content

Commit

Permalink
Simplify testing nightly builds with clusterctl
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Jan 17, 2024
1 parent 2ab8986 commit 63b19b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
29 changes: 22 additions & 7 deletions cmd/clusterctl/hack/create-local-repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@

from __future__ import unicode_literals

import sys
import errno
import json
import os
import subprocess
import urllib.request
from distutils.dir_util import copy_tree
from distutils.file_util import copy_file

Expand All @@ -68,19 +70,19 @@
'configFolder': 'controlplane/kubeadm/config/default',
},
'infrastructure-docker': {
'componentsFile': 'infrastructure-components.yaml',
'componentsFile': 'infrastructure-components-development.yaml',
'nextVersion': 'v1.7.99',
'type': 'InfrastructureProvider',
'configFolder': 'test/infrastructure/docker/config/default',
},
'infrastructure-in-memory': {
'componentsFile': 'infrastructure-components.yaml',
'componentsFile': 'infrastructure-components-development.yaml',
'nextVersion': 'v1.7.99',
'type': 'InfrastructureProvider',
'configFolder': 'test/infrastructure/inmemory/config/default',
},
'runtime-extension-test': {
'componentsFile': 'runtime-extension-components.yaml',
'componentsFile': 'runtime-extension-components-development.yaml',
'nextVersion': 'v1.7.99',
'type': 'RuntimeExtensionProvider',
'configFolder': 'test/extension/config/default',
Expand Down Expand Up @@ -167,6 +169,9 @@ def create_local_repositories():
assert providerList is not None, 'invalid configuration: please define the list of providers to override'
assert len(providerList)>0, 'invalid configuration: please define at least one provider to override'

if len(sys.argv) == 1:
execCmd(['make', 'kustomize'])

for provider in providerList:
p = providers.get(provider)
assert p is not None, 'invalid configuration: please specify the configuration for the {} provider'.format(
Expand All @@ -188,10 +193,16 @@ def create_local_repositories():
assert components_file is not None, 'invalid configuration for provider {}: please provide componentsFile value'.format(
provider)

execCmd(['make', 'kustomize'])
components_yaml = execCmd(['./hack/tools/bin/kustomize', 'build', os.path.join(repo, config_folder)])
if len(sys.argv) > 1:
url = "{}/{}".format(sys.argv[1], components_file)
print(url)
components_yaml = urllib.request.urlopen(url).read()
else:
execCmd(['make', 'kustomize'])
components_yaml = execCmd(['./hack/tools/bin/kustomize', 'build', os.path.join(repo, config_folder)])

components_path = write_local_repository(provider, next_version, components_file, components_yaml,
metadata_file)
metadata_file)

yield name, type, next_version, components_path

Expand Down Expand Up @@ -289,7 +300,11 @@ def print_instructions(repos):
cmd = "clusterctl init \\\n"
for name, type, next_version, components_path in repos:
cmd += " {} {}:{} \\\n".format(type_to_flag(type), name, next_version)
cmd += " --config $XDG_CONFIG_HOME/cluster-api/dev-repository/config.yaml"
config_dir = os.getenv("XDG_CONFIG_HOME", "")
if config_dir != "":
cmd += " --config $XDG_CONFIG_HOME/cluster-api/dev-repository/config.yaml"
else:
cmd += " --config $HOME/.config/cluster-api/dev-repository/config.yaml"
print(cmd)
print
if 'infrastructure-docker' in providerList:
Expand Down
25 changes: 20 additions & 5 deletions docs/book/src/clusterctl/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,35 @@ clusterctl init \
```

As you might notice, the command is using the `$XDG_CONFIG_HOME/cluster-api/dev-repository/config.yaml` config file,
containing all the required setting to make clusterctl use the local repository.
containing all the required setting to make clusterctl use the local repository (it fallbacks to `$HOME` if `$XDG_CONFIG_HOME`
is not set on your machine).

<aside class="note warning">

<h1>Warnings</h1>

You must pass `--config $XDG_CONFIG_HOME/cluster-api/dev-repository/config.yaml` to all the clusterctl commands you are running
during your dev session.
You must pass `--config ...` to all the clusterctl commands you are running during your dev session.

The above config file changes the location of the [overrides layer] folder thus ensuring
you dev session isn't hijacked by other local artifacts.

With the only exception of the Docker provider, the local repository folder does not contain cluster templates,
so the `clusterctl generate cluster` command will fail.
With the exceptions of the Docker and the in memory provider, the local repository folder does not contain cluster templates,
so the `clusterctl generate cluster` command will fail if you don't copy a template into the local repository.

</aside>

<aside class="note warning">

<h1>Nightly builds</h1>

if you want to run your tests using a Cluster API nightly build, you can run the hack passing the nightly build folder
(change the date at the end of the bucket name according to your needs):

```bash
cmd/clusterctl/hack/create-local-repository.py https://storage.googleapis.com/artifacts.k8s-staging-cluster-api.appspot.com/components/nightly_main_20240101
```

Note: this works only with core Cluster API nightly builds.

</aside>

Expand Down
5 changes: 4 additions & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
kind: Metadata
releaseSeries:
- major: 1
minor: 7
contract: v1beta1
- major: 1
minor: 6
contract: v1beta1
Expand All @@ -29,4 +32,4 @@ releaseSeries:
contract: v1beta1
- major: 0
minor: 4
contract: v1alpha4
contract: v1alpha4

0 comments on commit 63b19b9

Please sign in to comment.