diff --git a/changelog/65565.deprecated.md b/changelog/65565.deprecated.md new file mode 100644 index 000000000000..95c4b572265a --- /dev/null +++ b/changelog/65565.deprecated.md @@ -0,0 +1 @@ +Deprecate Kubernetes modules for move to saltext-kubernetes in version 3009 diff --git a/salt/modules/k8s.py b/salt/modules/k8s.py index 3368a1d547b2..9c3095b9308b 100644 --- a/salt/modules/k8s.py +++ b/salt/modules/k8s.py @@ -23,6 +23,12 @@ import salt.utils.http as http import salt.utils.json +__deprecated__ = ( + 3009, + "kubernetes", + "https://github.com/salt-extensions/saltext-kubernetes", +) + __virtualname__ = "k8s" # Setup the logger @@ -174,14 +180,14 @@ def _guess_node_id(node): def _get_labels(node, apiserver_url): """Get all labels from a kube node.""" # Prepare URL - url = "{}/api/v1/nodes/{}".format(apiserver_url, node) + url = f"{apiserver_url}/api/v1/nodes/{node}" # Make request ret = http.query(url) # Check requests status if "body" in ret: ret = salt.utils.json.loads(ret.get("body")) elif ret.get("status", 0) == 404: - return "Node {} doesn't exist".format(node) + return f"Node {node} doesn't exist" else: return ret # Get and return labels @@ -191,13 +197,13 @@ def _get_labels(node, apiserver_url): def _set_labels(node, apiserver_url, labels): """Replace labels dict by a new one""" # Prepare URL - url = "{}/api/v1/nodes/{}".format(apiserver_url, node) + url = f"{apiserver_url}/api/v1/nodes/{node}" # Prepare data data = [{"op": "replace", "path": "/metadata/labels", "value": labels}] # Make request ret = _kpatch(url, data) if ret.get("status") == 404: - return "Node {} doesn't exist".format(node) + return f"Node {node} doesn't exist" return ret @@ -264,9 +270,9 @@ def label_present(name, value, node=None, apiserver_url=None): # there is an update during operation, need to retry log.debug("Got 409, will try later") ret["changes"] = {} - ret["comment"] = "Could not create label {}, please retry".format(name) + ret["comment"] = f"Could not create label {name}, please retry" else: - ret["comment"] = "Label {} created".format(name) + ret["comment"] = f"Label {name} created" elif labels.get(name) != str(value): # This is a old label and we are going to edit it ret["changes"] = {name: str(value)} @@ -276,12 +282,12 @@ def label_present(name, value, node=None, apiserver_url=None): # there is an update during operation, need to retry log.debug("Got 409, will try later") ret["changes"] = {} - ret["comment"] = "Could not update label {}, please retry".format(name) + ret["comment"] = f"Could not update label {name}, please retry" else: - ret["comment"] = "Label {} updated".format(name) + ret["comment"] = f"Label {name} updated" else: # This is a old label and it has already the wanted value - ret["comment"] = "Label {} already set".format(name) + ret["comment"] = f"Label {name} already set" return ret @@ -316,7 +322,7 @@ def label_absent(name, node=None, apiserver_url=None): # Compare old labels and what we want if labels == old_labels: # Label already absent - ret["comment"] = "Label {} already absent".format(name) + ret["comment"] = f"Label {name} already absent" else: # Label needs to be delete res = _set_labels(node, apiserver_url, labels) @@ -324,10 +330,10 @@ def label_absent(name, node=None, apiserver_url=None): # there is an update during operation, need to retry log.debug("Got 409, will try later") ret["changes"] = {} - ret["comment"] = "Could not delete label {}, please retry".format(name) + ret["comment"] = f"Could not delete label {name}, please retry" else: ret["changes"] = {"deleted": name} - ret["comment"] = "Label {} absent".format(name) + ret["comment"] = f"Label {name} absent" return ret @@ -365,7 +371,7 @@ def label_folder_absent(name, node=None, apiserver_url=None): # Prepare a temp labels dict if labels == old_labels: # Label already absent - ret["comment"] = "Label folder {} already absent".format(folder) + ret["comment"] = f"Label folder {folder} already absent" else: # Label needs to be delete res = _set_labels(node, apiserver_url, labels) @@ -377,7 +383,7 @@ def label_folder_absent(name, node=None, apiserver_url=None): ) else: ret["changes"] = {"deleted": folder} - ret["comment"] = "Label folder {} absent".format(folder) + ret["comment"] = f"Label folder {folder} absent" return ret @@ -386,7 +392,7 @@ def label_folder_absent(name, node=None, apiserver_url=None): def _get_namespaces(apiserver_url, name=""): """Get namespace is namespace is defined otherwise return all namespaces""" # Prepare URL - url = "{}/api/v1/namespaces/{}".format(apiserver_url, name) + url = f"{apiserver_url}/api/v1/namespaces/{name}" # Make request ret = http.query(url) if ret.get("body"): @@ -398,7 +404,7 @@ def _get_namespaces(apiserver_url, name=""): def _create_namespace(namespace, apiserver_url): """create namespace on the defined k8s cluster""" # Prepare URL - url = "{}/api/v1/namespaces".format(apiserver_url) + url = f"{apiserver_url}/api/v1/namespaces" # Prepare data data = {"kind": "Namespace", "apiVersion": "v1", "metadata": {"name": namespace}} log.trace("namespace creation requests: %s", data) @@ -438,9 +444,9 @@ def create_namespace(name, apiserver_url=None): # This is a new namespace _create_namespace(name, apiserver_url) ret["changes"] = name - ret["comment"] = "Namespace {} created".format(name) + ret["comment"] = f"Namespace {name} created" else: - ret["comment"] = "Namespace {} already present".format(name) + ret["comment"] = f"Namespace {name} already present" return ret @@ -484,7 +490,7 @@ def get_namespaces(namespace="", apiserver_url=None): def _get_secrets(namespace, name, apiserver_url): """Get secrets of the namespace.""" # Prepare URL - url = "{}/api/v1/namespaces/{}/secrets/{}".format(apiserver_url, namespace, name) + url = f"{apiserver_url}/api/v1/namespaces/{namespace}/secrets/{name}" # Make request ret = http.query(url) if ret.get("body"): @@ -496,20 +502,20 @@ def _get_secrets(namespace, name, apiserver_url): def _update_secret(namespace, name, data, apiserver_url): """Replace secrets data by a new one""" # Prepare URL - url = "{}/api/v1/namespaces/{}/secrets/{}".format(apiserver_url, namespace, name) + url = f"{apiserver_url}/api/v1/namespaces/{namespace}/secrets/{name}" # Prepare data data = [{"op": "replace", "path": "/data", "value": data}] # Make request ret = _kpatch(url, data) if ret.get("status") == 404: - return "Node {} doesn't exist".format(url) + return f"Node {url} doesn't exist" return ret def _create_secret(namespace, name, data, apiserver_url): """create namespace on the defined k8s cluster""" # Prepare URL - url = "{}/api/v1/namespaces/{}/secrets".format(apiserver_url, namespace) + url = f"{apiserver_url}/api/v1/namespaces/{namespace}/secrets" # Prepare data request = { "apiVersion": "v1", @@ -738,7 +744,7 @@ def create_secret( return { "name": name, "result": False, - "comment": "Secret {} is already present".format(name), + "comment": f"Secret {name} is already present", "changes": {}, } @@ -755,7 +761,7 @@ def create_secret( if sname == encoded == "": ret[ "comment" - ] += "Source file {} is missing or name is incorrect\n".format(v) + ] += f"Source file {v} is missing or name is incorrect\n" if force: continue else: @@ -825,8 +831,8 @@ def delete_secret(namespace, name, apiserver_url=None, force=True): "changes": {}, } - url = "{}/api/v1/namespaces/{}/secrets/{}".format(apiserver_url, namespace, name) + url = f"{apiserver_url}/api/v1/namespaces/{namespace}/secrets/{name}" res = http.query(url, method="DELETE") if res.get("body"): - ret["comment"] = "Removed secret {} in {} namespace".format(name, namespace) + ret["comment"] = f"Removed secret {name} in {namespace} namespace" return ret diff --git a/salt/modules/kubeadm.py b/salt/modules/kubeadm.py index 7ffd59be8313..d2a14f73e7e3 100644 --- a/salt/modules/kubeadm.py +++ b/salt/modules/kubeadm.py @@ -17,6 +17,12 @@ log = logging.getLogger(__name__) +__deprecated__ = ( + 3009, + "kubernetes", + "https://github.com/salt-extensions/saltext-kubernetes", +) + __virtualname__ = "kubeadm" # Define not exported variables from Salt, so this can be imported as @@ -139,7 +145,7 @@ def version(kubeconfig=None, rootfs=None): parameters = [("kubeconfig", kubeconfig), ("rootfs", rootfs)] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) cmd.extend(["--output", "json"]) @@ -226,9 +232,9 @@ def token_create( for parameter, value in parameters: if value: if parameter in ("groups", "usages"): - cmd.extend(["--{}".format(parameter), json.dumps(value)]) + cmd.extend([f"--{parameter}", json.dumps(value)]) else: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -264,7 +270,7 @@ def token_delete(token, kubeconfig=None, rootfs=None): parameters = [("kubeconfig", kubeconfig), ("rootfs", rootfs)] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return bool(_cmd(cmd)) @@ -295,7 +301,7 @@ def token_generate(kubeconfig=None, rootfs=None): parameters = [("kubeconfig", kubeconfig), ("rootfs", rootfs)] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -325,7 +331,7 @@ def token_list(kubeconfig=None, rootfs=None): parameters = [("kubeconfig", kubeconfig), ("rootfs", rootfs)] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) lines = _cmd(cmd).splitlines() @@ -368,7 +374,7 @@ def alpha_certs_renew(rootfs=None): parameters = [("rootfs", rootfs)] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -430,7 +436,7 @@ def alpha_kubeconfig_user( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -469,7 +475,7 @@ def alpha_kubelet_config_download(kubeconfig=None, kubelet_version=None, rootfs= ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -520,7 +526,7 @@ def alpha_kubelet_config_enable_dynamic( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -574,7 +580,7 @@ def alpha_selfhosting_pivot( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -627,7 +633,7 @@ def config_images_list( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd).splitlines() @@ -685,7 +691,7 @@ def config_images_pull( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) prefix = "[config/images] Pulled " return [(line.replace(prefix, "")) for line in _cmd(cmd).splitlines()] @@ -729,7 +735,7 @@ def config_migrate(old_config, new_config=None, kubeconfig=None, rootfs=None): ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -769,7 +775,7 @@ def config_print_init_defaults(component_configs=None, kubeconfig=None, rootfs=N ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -809,7 +815,7 @@ def config_print_join_defaults(component_configs=None, kubeconfig=None, rootfs=N ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -843,7 +849,7 @@ def config_upload_from_file(config, kubeconfig=None, rootfs=None): parameters = [("kubeconfig", kubeconfig), ("rootfs", rootfs)] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -940,7 +946,7 @@ def config_upload_from_flags( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -970,7 +976,7 @@ def config_view(kubeconfig=None, rootfs=None): parameters = [("kubeconfig", kubeconfig), ("rootfs", rootfs)] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -1132,7 +1138,7 @@ def init( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -1297,7 +1303,7 @@ def join( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) @@ -1364,7 +1370,7 @@ def reset( ] for parameter, value in parameters: if value: - cmd.extend(["--{}".format(parameter), str(value)]) + cmd.extend([f"--{parameter}", str(value)]) return _cmd(cmd) diff --git a/salt/modules/kubernetesmod.py b/salt/modules/kubernetesmod.py index 4755d4cf212e..a0a3f2de44e0 100644 --- a/salt/modules/kubernetesmod.py +++ b/salt/modules/kubernetesmod.py @@ -85,6 +85,12 @@ log = logging.getLogger(__name__) +__deprecated__ = ( + 3009, + "kubernetes", + "https://github.com/salt-extensions/saltext-kubernetes", +) + __virtualname__ = "kubernetes" @@ -1099,7 +1105,7 @@ def create_secret( source=None, template=None, saltenv="base", - **kwargs + **kwargs, ): """ Creates the kubernetes secret as defined by the user. @@ -1274,7 +1280,7 @@ def replace_service( old_service, saltenv, namespace="default", - **kwargs + **kwargs, ): """ Replaces an existing service with a new one defined by name and namespace, @@ -1324,7 +1330,7 @@ def replace_secret( template=None, saltenv="base", namespace="default", - **kwargs + **kwargs, ): """ Replaces an existing secret with a new one defined by name and namespace, @@ -1379,7 +1385,7 @@ def replace_configmap( template=None, saltenv="base", namespace="default", - **kwargs + **kwargs, ): """ Replaces an existing configmap with a new one defined by name and @@ -1446,7 +1452,7 @@ def __create_object_body( or src_obj["kind"] != kind ): raise CommandExecutionError( - "The source file should define only a {} object".format(kind) + f"The source file should define only a {kind} object" ) if "metadata" in src_obj: @@ -1467,7 +1473,7 @@ def __read_and_render_yaml_file(source, template, saltenv): """ sfn = __salt__["cp.cache_file"](source, saltenv) if not sfn: - raise CommandExecutionError("Source file '{}' not found".format(source)) + raise CommandExecutionError(f"Source file '{source}' not found") with salt.utils.files.fopen(sfn, "r") as src: contents = src.read() @@ -1496,9 +1502,7 @@ def __read_and_render_yaml_file(source, template, saltenv): contents = data["data"].encode("utf-8") else: - raise CommandExecutionError( - "Unknown template specified: {}".format(template) - ) + raise CommandExecutionError(f"Unknown template specified: {template}") return salt.utils.yaml.safe_load(contents) diff --git a/salt/states/kubernetes.py b/salt/states/kubernetes.py index ed78f34ab308..11141369fab2 100644 --- a/salt/states/kubernetes.py +++ b/salt/states/kubernetes.py @@ -85,6 +85,12 @@ log = logging.getLogger(__name__) +__deprecated__ = ( + 3009, + "kubernetes", + "https://github.com/salt-extensions/saltext-kubernetes", +) + def __virtual__(): """ @@ -136,7 +142,7 @@ def deployment_absent(name, namespace="default", **kwargs): ret["changes"] = {"kubernetes.deployment": {"new": "absent", "old": "present"}} ret["comment"] = res["message"] else: - ret["comment"] = "Something went wrong, response: {}".format(res) + ret["comment"] = f"Something went wrong, response: {res}" return ret @@ -148,7 +154,7 @@ def deployment_present( spec=None, source="", template="", - **kwargs + **kwargs, ): """ Ensures that the named deployment is present inside of the specified @@ -203,9 +209,9 @@ def deployment_present( source=source, template=template, saltenv=__env__, - **kwargs + **kwargs, ) - ret["changes"]["{}.{}".format(namespace, name)] = {"old": {}, "new": res} + ret["changes"][f"{namespace}.{name}"] = {"old": {}, "new": res} else: if __opts__["test"]: ret["result"] = None @@ -222,7 +228,7 @@ def deployment_present( source=source, template=template, saltenv=__env__, - **kwargs + **kwargs, ) ret["changes"] = {"metadata": metadata, "spec": spec} @@ -237,7 +243,7 @@ def service_present( spec=None, source="", template="", - **kwargs + **kwargs, ): """ Ensures that the named service is present inside of the specified namespace @@ -292,9 +298,9 @@ def service_present( source=source, template=template, saltenv=__env__, - **kwargs + **kwargs, ) - ret["changes"]["{}.{}".format(namespace, name)] = {"old": {}, "new": res} + ret["changes"][f"{namespace}.{name}"] = {"old": {}, "new": res} else: if __opts__["test"]: ret["result"] = None @@ -312,7 +318,7 @@ def service_present( template=template, old_service=service, saltenv=__env__, - **kwargs + **kwargs, ) ret["changes"] = {"metadata": metadata, "spec": spec} @@ -351,7 +357,7 @@ def service_absent(name, namespace="default", **kwargs): ret["changes"] = {"kubernetes.service": {"new": "absent", "old": "present"}} ret["comment"] = res["message"] else: - ret["comment"] = "Something went wrong, response: {}".format(res) + ret["comment"] = f"Something went wrong, response: {res}" return ret @@ -391,7 +397,7 @@ def namespace_absent(name, **kwargs): else: ret["comment"] = "Terminating" else: - ret["comment"] = "Something went wrong, response: {}".format(res) + ret["comment"] = f"Something went wrong, response: {res}" return ret @@ -506,9 +512,9 @@ def secret_present( source=source, template=template, saltenv=__env__, - **kwargs + **kwargs, ) - ret["changes"]["{}.{}".format(namespace, name)] = {"old": {}, "new": res} + ret["changes"][f"{namespace}.{name}"] = {"old": {}, "new": res} else: if __opts__["test"]: ret["result"] = None @@ -525,7 +531,7 @@ def secret_present( source=source, template=template, saltenv=__env__, - **kwargs + **kwargs, ) ret["changes"] = { @@ -620,9 +626,9 @@ def configmap_present( source=source, template=template, saltenv=__env__, - **kwargs + **kwargs, ) - ret["changes"]["{}.{}".format(namespace, name)] = {"old": {}, "new": res} + ret["changes"][f"{namespace}.{name}"] = {"old": {}, "new": res} else: if __opts__["test"]: ret["result"] = None @@ -639,7 +645,7 @@ def configmap_present( source=source, template=template, saltenv=__env__, - **kwargs + **kwargs, ) ret["changes"] = {"data": res["data"]} @@ -681,7 +687,7 @@ def pod_absent(name, namespace="default", **kwargs): else: ret["comment"] = res["message"] else: - ret["comment"] = "Something went wrong, response: {}".format(res) + ret["comment"] = f"Something went wrong, response: {res}" return ret @@ -693,7 +699,7 @@ def pod_present( spec=None, source="", template="", - **kwargs + **kwargs, ): """ Ensures that the named pod is present inside of the specified @@ -748,9 +754,9 @@ def pod_present( source=source, template=template, saltenv=__env__, - **kwargs + **kwargs, ) - ret["changes"]["{}.{}".format(namespace, name)] = {"old": {}, "new": res} + ret["changes"][f"{namespace}.{name}"] = {"old": {}, "new": res} else: if __opts__["test"]: ret["result"] = None @@ -896,7 +902,7 @@ def node_label_present(name, node, value, **kwargs): old_labels = copy.copy(labels) labels[name] = value - ret["changes"]["{}.{}".format(node, name)] = {"old": old_labels, "new": labels} + ret["changes"][f"{node}.{name}"] = {"old": old_labels, "new": labels} ret["result"] = True return ret