diff --git a/.github/workflows/canary-integration-test.yml b/.github/workflows/canary-integration-test.yml index 3da8fdbe2..b68dcbb37 100644 --- a/.github/workflows/canary-integration-test.yml +++ b/.github/workflows/canary-integration-test.yml @@ -68,7 +68,8 @@ jobs: run: | toolbox=$(kubectl get pod -l app=rook-ceph-tools -n rook-ceph -o jsonpath='{.items[*].metadata.name}') kubectl -n rook-ceph exec $toolbox -- mkdir -p /etc/ceph/test-data - kubectl -n rook-ceph cp tests/ceph-status-out $toolbox:/etc/ceph/test-data/ + kubectl -n rook-ceph cp tests/external-cluster/ceph-status-out $toolbox:/etc/ceph/test-data/ + kubectl -n rook-ceph cp tests/external-cluster/external-config.ini $toolbox:/etc/ceph/ kubectl -n rook-ceph cp deploy/examples/create-external-cluster-resources.py $toolbox:/etc/ceph kubectl -n rook-ceph cp deploy/examples/create-external-cluster-resources-tests.py $toolbox:/etc/ceph timeout 10 sh -c "until kubectl -n rook-ceph exec $toolbox -- python3 /etc/ceph/create-external-cluster-resources.py --rbd-data-pool-name replicapool; do echo 'waiting for script to succeed' && sleep 1; done" @@ -267,6 +268,29 @@ jobs: toolbox=$(kubectl get pod -l app=rook-ceph-tools -n rook-ceph -o jsonpath='{.items[*].metadata.name}') kubectl -n rook-ceph exec $toolbox -- python3 /etc/ceph/create-external-cluster-resources.py --rbd-data-pool-name replicapool --v2-port-enable + - name: test config file flag + run: | + toolbox=$(kubectl get pod -l app=rook-ceph-tools -n rook-ceph -o jsonpath='{.items[*].metadata.name}') + # create `radosNamespace2` rados-namespace for `replicapool` rbd data-pool + kubectl -n rook-ceph exec $toolbox -- rbd namespace create replicapool/radosnamespace2 + + # validate `--rados-namespace`, config file value is radosnamespace2, cli arg flag is set to radosnamespace1 and no default is set + # command line arg should be used + kubectl -n rook-ceph exec $toolbox -- python3 /etc/ceph/create-external-cluster-resources.py --rbd-data-pool-name replicapool --rados-namespace radosnamespace1 --config-file /etc/ceph/external-config.ini + + # validate the `rbd-data-pool-name`,config value set to replicapoolconfig, command line arg is not set and no default + # config value should be used + sed -i 's/replicapool/replicapoolconfig/' deploy/examples/pool-test.yaml + kubectl create -f deploy/examples/pool-test.yaml + kubectl wait --for='jsonpath={.status.phase}=Ready' Cephblockpool/replicapoolconfig -nrook-ceph + # create `radosNamespace2` rados-namespace for `replicapoolconfig` rbd data-pool + kubectl -n rook-ceph exec $toolbox -- rbd namespace create replicapoolconfig/radosnamespace2 + kubectl -n rook-ceph exec $toolbox -- python3 /etc/ceph/create-external-cluster-resources.py --config-file /etc/ceph/external-config.ini + + # validate the default `format`` flag, config file value is not set and no cmd line argument is set and default value is `Json``, + # default value should be used + kubectl -n rook-ceph exec $toolbox -- python3 /etc/ceph/create-external-cluster-resources.py --rbd-data-pool-name replicapool --config-file /etc/ceph/external-config.ini + - name: check-ownerreferences run: tests/scripts/github-action-helper.sh check_ownerreferences diff --git a/Documentation/CRDs/Cluster/external-cluster/external-cluster.md b/Documentation/CRDs/Cluster/external-cluster/external-cluster.md index da67cf44c..97dd82738 100644 --- a/Documentation/CRDs/Cluster/external-cluster/external-cluster.md +++ b/Documentation/CRDs/Cluster/external-cluster/external-cluster.md @@ -63,6 +63,32 @@ python3 create-external-cluster-resources.py --rbd-data-pool-name -- * `--topology-pools`: (optional) Comma-separated list of topology-constrained rbd pools * `--topology-failure-domain-label`: (optional) K8s cluster failure domain label (example: zone, rack, or host) for the topology-pools that match the ceph domain * `--topology-failure-domain-values`: (optional) Comma-separated list of the k8s cluster failure domain values corresponding to each of the pools in the `topology-pools` list +* `--config-file`: Path to the configuration file, Priority: command-line-args > config.ini values > default values + +### Config-file + +Use the config file to set the user configuration file, add the flag `--config-file` to set the file path. + +Example: + +`/config.ini` + +```console +[Configurations] +format = bash +cephfs-filesystem-name = +rbd-data-pool-name = +... +``` + +```console +python3 create-external-cluster-resources.py --config-file /config.ini +``` + +!!! note + You can use both config file and other arguments at the same time + Priority: command-line-args > config.ini file values > default values + ### Multi-tenancy diff --git a/deploy/examples/create-external-cluster-resources.py b/deploy/examples/create-external-cluster-resources.py index e0ccbcaf9..09960ff43 100644 --- a/deploy/examples/create-external-cluster-resources.py +++ b/deploy/examples/create-external-cluster-resources.py @@ -21,6 +21,7 @@ import argparse import re import subprocess import hmac +import configparser from hashlib import sha1 as sha from os import linesep as LINESEP from os import path @@ -478,6 +479,15 @@ class RadosJSON: + "Upgrade flag should only be used to append new permissions to users, it shouldn't be used for changing user already applied permission, for example you shouldn't change in which pool user has access", ) + # Add command-line arguments + config_group = argP.add_argument_group("config") + config_group.add_argument( + "--config-file", + type=str, + help="Path to the configuration file, Priority: command-line-args > config.ini file values > default values", + required=False, + ) + if args_to_parse: assert ( type(args_to_parse) == list @@ -617,10 +627,31 @@ class RadosJSON: ("-1"), ) + def parse_config_file(self, config_file): + config = configparser.ConfigParser() + config.read(config_file) + for arg in list(vars(self._arg_parser)): + # python treats flag-name as flag_name internally, so converting back to flag-name, + # so we can get those values from config file + argument = arg.replace("_", "-") + argumentValue = str(getattr(self._arg_parser, arg)) + config_value = config.get("Configurations", argument, fallback=None) + # give priority to command line argument, if command line argument is not present use config.ini value, + if ( + (str(sys.argv).find(argument) == -1) + and ((argumentValue is None) or (argumentValue is "")) + and ((config_value is not None) and (config_value is not "")) + ): + self._arg_parser.__setattr__(arg, config_value) + + return config + def __init__(self, arg_list=None): self.out_map = {} self._excluded_keys = set() self._arg_parser = self.gen_arg_parser(args_to_parse=arg_list) + if self._arg_parser.config_file: + self.config = self.parse_config_file(self._arg_parser.config_file) self._check_conflicting_options() self.run_as_user = self._arg_parser.run_as_user self.output_file = self._arg_parser.output diff --git a/images/ceph/Makefile b/images/ceph/Makefile index 77570c1f6..10f9e9091 100755 --- a/images/ceph/Makefile +++ b/images/ceph/Makefile @@ -60,7 +60,6 @@ do.build: @cp -r $(MANIFESTS_DIR)/monitoring $(BUILD_CONTEXT_DIR)/ceph-monitoring @mkdir -p $(BUILD_CONTEXT_DIR)/rook-external/test-data @cp $(MANIFESTS_DIR)/create-external-cluster-resources.* $(BUILD_CONTEXT_DIR)/rook-external/ - @cp ../../tests/ceph-status-out $(BUILD_CONTEXT_DIR)/rook-external/test-data/ @cd $(BUILD_CONTEXT_DIR) && $(SED_IN_PLACE) 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile @if [ -z "$(BUILD_CONTAINER_IMAGE)" ]; then\ $(DOCKERCMD) build $(BUILD_ARGS) \ diff --git a/tests/ceph-status-out b/tests/external-cluster/ceph-status-out similarity index 100% rename from tests/ceph-status-out rename to tests/external-cluster/ceph-status-out diff --git a/tests/external-cluster/external-config.ini b/tests/external-cluster/external-config.ini new file mode 100644 index 000000000..20ede38d4 --- /dev/null +++ b/tests/external-cluster/external-config.ini @@ -0,0 +1,35 @@ +[Configurations] +format = +verbose = +ceph-conf = +keyring = +run-as-user = +cluster-name = +k8s-cluster-name = +namespace = +rgw-pool-prefix = +restricted-auth-permission = +v2-port-enable = +output = +cephfs-filesystem-name = +cephfs-metadata-pool-name = +cephfs-data-pool-name = +rbd-data-pool-name = replicapoolconfig +alias-rbd-data-pool-name = +rgw-endpoint = +rgw-tls-cert-path = +rgw-skip-tls = +monitoring-endpoint = +monitoring-endpoint-port = +skip-monitoring-endpoint = +rbd-metadata-ec-pool-name = +dry-run = +rados-namespace = radosnamespace2 +subvolume-group = +rgw-realm-name = +rgw-zone-name = +rgw-zonegroup-name = +topology-pool = +topology-failure-domain-label = +topology-failure-domain-values = +upgrade =