Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Jan 9, 2020
1 parent fe4d60d commit 4213d71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
31 changes: 14 additions & 17 deletions cmd/clusterctl/hack/local-overrides.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2015 The Kubernetes Authors.
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,7 @@
# - there should be a sigs.k8s.io/cluster-api/clusterctl-settings.json file with the list of provider for which
# the local overrides should be generated and the list of provider repositories to be included (on top of cluster-api).
# {
# "providers": [ "cluster-api", "kubeadm", "aws"],
# "providers": [ "cluster-api", "kubeadm-bootstrap", "aws"],
# "provider_repos": ["../cluster-api-provider-aws"]
# }
# - for each additional provider repository there should be a sigs.k8s.io/<provider_repo>/clusterctl-settings.json file e.g.
Expand All @@ -52,22 +52,24 @@
'nextVersion': 'v0.3.0',
'type': 'CoreProvider',
},
'kubeadm': {
'kubeadm-bootstrap': {
'componentsFile': 'bootstrap-components.yaml',
'nextVersion': 'v0.3.0',
'type': 'BootstrapProvider',
'configFolder': '/bootstrap/kubeadm/config/default',
},
}

validTypes = ['CoreProvider','BootstrapProvider','InfrastructureProvider']

def load_settings():
global settings
try:
settings = json.load(open('clusterctl-settings.json'))
except Exception as e:
raise Exception('failed to load clusterctl-settings.json: {}'.format(e))

def load_provider():
def load_providers():
provider_repos = settings.get('provider_repos', [])
for repo in provider_repos:
file = repo + '/clusterctl-settings.json'
Expand All @@ -80,7 +82,7 @@ def load_provider():
except Exception as e:
raise Exception('failed to load clusterctl-settings.json from repo {}: {}'.format(repo, e))

def kustomize(args):
def execCmd(args):
try:
out = subprocess.Popen(args,
stdout=subprocess.PIPE,
Expand Down Expand Up @@ -115,32 +117,27 @@ def write_local_override(provider, version, components_file, components_yaml):

def create_local_overrides():
providerList = settings.get('providers', [])
assert providerList is not None, 'invalid configuration: please define the list of providers to overrides'
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'

for provider in providerList:
p = providers.get(provider)
assert p is not None, 'invalid configuration: please the configuration for the {} provider'.format(provider)

repo = '.'
if 'repo' in p:
repo = p.get('repo')
assert p is not None, 'invalid configuration: please specify the configuration for the {} provider'.format(provider)

config_folder = '/config/default'
if 'configFolder' in p:
config_folder = p.get('configFolder')
repo = p.get('repo', '.')
config_folder = p.get('configFolder', '/config/default')

next_version = p.get('nextVersion')
assert next_version is not None, 'invalid configuration for provider {}: please provide nextVersion value'.format(provider)

type = p.get('type')
assert type is not None, 'invalid configuration for provider {}: please provide type value'.format(provider)
assert type in ['CoreProvider','BootstrapProvider','InfrastructureProvider'], 'invalid configuration for provider {}: please provide type value'.format(provider)
assert type in validTypes, 'invalid configuration for provider {}: please use one of {}'.format(provider, ', '.join(validTypes))

components_file = p.get('componentsFile')
assert components_file is not None, 'invalid configuration for provider {}: please provide componentsFile value'.format(provider)

components_yaml = kustomize(['kustomize', 'build', repo + config_folder])
components_yaml = execCmd(['kustomize', 'build', repo + config_folder])
write_local_override(provider, next_version, components_file, components_yaml)

yield provider, type, next_version
Expand Down Expand Up @@ -177,7 +174,7 @@ def print_instructions(overrides):

load_settings()

load_provider()
load_providers()

overrides = create_local_overrides()

Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/pkg/client/config/providers_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

const (
ClusterAPIName = "cluster-api"
KubeadmBootstrapProviderName = "kubeadm"
KubeadmBootstrapProviderName = "kubeadm-bootstrap"
ProvidersConfigKey = "providers"
)

Expand Down

0 comments on commit 4213d71

Please sign in to comment.