Skip to content

Commit 558ddc3

Browse files
Add concurrency option for helmfile commands (#81)
* Add concurrency option for helmfile commands * Address reviews * Add functionality for parsing unknown args
1 parent 7218b70 commit 558ddc3

File tree

11 files changed

+47
-27
lines changed

11 files changed

+47
-27
lines changed

src/ops/cli/config_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from himl.main import ConfigRunner
1313
from ops.cli.parser import SubParserConfig
1414

15+
logger = logging.getLogger(__name__)
1516

1617
class ConfigGeneratorParserConfig(SubParserConfig):
1718
def get_name(self):
@@ -35,7 +36,8 @@ class ConfigGeneratorRunner(object):
3536
def __init__(self, cluster_config_path):
3637
self.cluster_config_path = cluster_config_path
3738

38-
def run(self, args):
39+
def run(self, args, extra_args):
40+
logger.info("Found extra_args %s", extra_args)
3941
logging.basicConfig(level=logging.INFO)
4042
args.path = self.cluster_config_path
4143
if args.output_file is None:

src/ops/cli/helmfile.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ def get_help(self):
2929
return 'Wrap common helmfile tasks using hierarchical configuration support'
3030

3131
def configure(self, parser):
32-
parser.add_argument(
33-
'subcommand',
34-
help='plan | sync | apply | template',
35-
type=str)
36-
parser.add_argument(
37-
'extra_args',
38-
type=str,
39-
nargs='*',
40-
help='Extra args')
4132
parser.add_argument(
4233
'--helmfile-path',
4334
type=str,
@@ -51,7 +42,9 @@ def get_epilog(self):
5142
# Run helmfile sync
5243
ops data/env=dev/region=va6/project=ee/cluster=experiments/composition=helmfiles helmfile sync
5344
# Run helmfile sync for a single chart
54-
ops data/env=dev/region=va6/project=ee/cluster=experiments/composition=helmfiles helmfile sync -- --selector chart=nginx-controller
45+
ops data/env=dev/region=va6/project=ee/cluster=experiments/composition=helmfiles helmfile --selector chart=nginx-controller sync
46+
# Run helmfile sync with concurrency flag
47+
ops data/env=dev/region=va6/project=ee/cluster=experiments/composition=helmfiles helmfile --selector chart=nginx-controller sync --concurrency=1
5548
'''
5649

5750

@@ -63,7 +56,7 @@ def __init__(self, ops_config, cluster_config_path, execute):
6356
self.cluster_config_path = cluster_config_path
6457
self.execute = execute
6558

66-
def run(self, args):
59+
def run(self, args, extra_args):
6760
config_path_prefix = os.path.join(self.cluster_config_path, '')
6861
default_helmfiles = '../ee-k8s-infra/compositions/helmfiles'
6962
args.helmfile_path = default_helmfiles if args.helmfile_path is None else os.path.join(
@@ -79,7 +72,7 @@ def run(self, args):
7972
data = self.generate_helmfile_config(conf_path, args)
8073
self.setup_kube_config(data)
8174

82-
command = self.get_helmfile_command(args)
75+
command = self.get_helmfile_command(args, extra_args)
8376
return dict(command=command)
8477

8578
def setup_kube_config(self, data):
@@ -150,6 +143,8 @@ def generate_helmfile_config(self, path, args):
150143
output_file=output_file,
151144
print_data=True)
152145

153-
def get_helmfile_command(self, args):
154-
cmd = ' '.join(args.extra_args + [args.subcommand])
155-
return "cd {} && helmfile {}".format(args.helmfile_path, cmd)
146+
def get_helmfile_command(self, args, extra_args):
147+
helmfile_args = ' '.join(extra_args)
148+
return "cd {helmfile_path} && helmfile {helmfile_args}".format(
149+
helmfile_path=args.helmfile_path,
150+
helmfile_args=helmfile_args)

src/ops/cli/inventory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
# governing permissions and limitations under the License.
1010

1111
import yaml
12+
import logging
1213

1314
from ansible.parsing.yaml.dumper import AnsibleDumper
1415
from ansible.utils.color import stringc
1516
from . import display
1617
from .parser import configure_common_arguments, SubParserConfig
1718

19+
logger = logging.getLogger(__name__)
1820

1921
class InventoryParserConfig(SubParserConfig):
2022
def get_name(self):
@@ -45,7 +47,8 @@ def __init__(self, ansible_inventory, cluster_name):
4547
self.ansible_inventory = ansible_inventory
4648
self.cluster_name = cluster_name
4749

48-
def run(self, args):
50+
def run(self, args, extra_args):
51+
logger.info("Found extra_args %s", extra_args)
4952
for host in self.get_inventory_hosts(args):
5053
group_names = [group.name for group in host.get_groups()]
5154
group_names = sorted(group_names)

src/ops/cli/packer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
# OF ANY KIND, either express or implied. See the License for the specific language
99
# governing permissions and limitations under the License.
1010

11+
import logging
1112
from ops.cli.parser import SubParserConfig
1213
from . import aws
1314

15+
logger = logging.getLogger(__name__)
1416

1517
class PackerParserConfig(SubParserConfig):
1618
def get_name(self):
@@ -39,7 +41,8 @@ def __init__(self, root_dir, cluster_config):
3941
self.cluster_config = cluster_config
4042
self.root_dir = root_dir
4143

42-
def run(self, args):
44+
def run(self, args, extra_args):
45+
logger.info("Found extra_args %s", extra_args)
4346
config_all = self.cluster_config.all()
4447

4548
packer_variables = config_all['packer']['variables']

src/ops/cli/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def parse_args(self, args=None):
7575
RootParser._check_args_for_unicode(args)
7676
return self._get_parser().parse_args(args)
7777

78+
def parse_known_args(self, args=None):
79+
RootParser._check_args_for_unicode(args)
80+
return self._get_parser().parse_known_args(args)
81+
7882

7983
class SubParserConfig(object):
8084
def get_name(self):

src/ops/cli/playbook.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
from .parser import SubParserConfig
1212
from .parser import configure_common_ansible_args, configure_common_arguments
1313
import getpass
14+
import logging
1415

16+
logger = logging.getLogger(__name__)
1517

1618
class PlaybookParserConfig(SubParserConfig):
1719
def get_name(self):
@@ -66,7 +68,8 @@ def __init__(self, ops_config, root_dir, inventory_generator,
6668
self.cluster_config_path = cluster_config_path
6769
self.cluster_config = cluster_config
6870

69-
def run(self, args):
71+
def run(self, args, extra_args):
72+
logger.info("Found extra_args %s", extra_args)
7073
inventory_path, ssh_config_path = self.inventory_generator.generate()
7174

7275
ssh_config = "ANSIBLE_SSH_ARGS='-F %s'" % ssh_config_path

src/ops/cli/run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
# OF ANY KIND, either express or implied. See the License for the specific language
99
# governing permissions and limitations under the License.
1010

11+
import logging
1112
from .parser import configure_common_ansible_args, SubParserConfig
1213

14+
logger = logging.getLogger(__name__)
1315

1416
class CommandParserConfig(SubParserConfig):
1517
def get_epilog(self):
@@ -61,7 +63,8 @@ def __init__(self, ops_config, root_dir, inventory_generator,
6163
self.cluster_config_path = cluster_config_path
6264
self.cluster_config = cluster_config
6365

64-
def run(self, args):
66+
def run(self, args, extra_args):
67+
logger.info("Found extra_args %s", extra_args)
6568
inventory_path, ssh_config_path = self.inventory_generator.generate()
6669
limit = args.host_pattern
6770

src/ops/cli/ssh.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import getpass
2121
import re
2222
import os
23+
import logging
2324

25+
logger = logging.getLogger(__name__)
2426
IP_HOST_REG_EX = re.compile(r'^((\d+)\.(\d+)\.(\d+)\.(\d+):)?(\d+)$')
2527

2628

@@ -126,7 +128,8 @@ def __init__(self, cluster_config_path, cluster_config,
126128
self.cluster_config = cluster_config
127129
self.ansible_inventory = ansible_inventory
128130

129-
def run(self, args):
131+
def run(self, args, extra_args):
132+
logger.info("Found extra_args %s", extra_args)
130133
if args.keygen:
131134
if self.cluster_config.has_ssh_keys:
132135
err('Cluster already has ssh keys, refusing to overwrite')

src/ops/cli/sync.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
# OF ANY KIND, either express or implied. See the License for the specific language
99
# governing permissions and limitations under the License.
1010

11+
import logging
1112
import getpass
1213
import subprocess
1314

1415
from .parser import SubParserConfig
1516
from . import *
1617

18+
logger = logging.getLogger(__name__)
1719

1820
class SyncParserConfig(SubParserConfig):
1921
def configure(self, parser):
@@ -64,7 +66,8 @@ def __init__(self, cluster_config, root_dir,
6466
self.cluster_config = cluster_config
6567
self.ops_config = ops_config
6668

67-
def run(self, args):
69+
def run(self, args, extra_args):
70+
logger.info("Found extra_args %s", extra_args)
6871
inventory_path, ssh_config_path = self.inventory_generator.generate()
6972
src = PathExpr(args.src)
7073
dest = PathExpr(args.dest)

src/ops/cli/terraform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
logger = logging.getLogger(__name__)
2222

23-
2423
class TerraformParserConfig(SubParserConfig):
2524
def get_name(self):
2625
return 'terraform'
@@ -171,7 +170,8 @@ def check_ops_version(self):
171170
self.cluster_config.conf["terraform"]["ops_min_version"])
172171
validate_ops_version(ops_min_version)
173172

174-
def run(self, args):
173+
def run(self, args, extra_args):
174+
logger.info("Found extra_args %s", extra_args)
175175
self.check_ops_version()
176176
terraform_config_path = os.environ.get(
177177
"TF_CLI_CONFIG_FILE",

0 commit comments

Comments
 (0)