X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Fkubectl.py;h=31b6f55f6c50a436e8dfe4e508c35c42e4c39c0e;hp=9d4ce57a49b900fb7abc8b441cb3c1a324339239;hb=7077e2601a209a87f7fe397b35586e7701ca759a;hpb=37004983e8e484d5504ae4253bdb75204ff389d9 diff --git a/n2vc/kubectl.py b/n2vc/kubectl.py index 9d4ce57..31b6f55 100644 --- a/n2vc/kubectl.py +++ b/n2vc/kubectl.py @@ -22,6 +22,9 @@ class Kubectl: config.load_kube_config(config_file=config_file) self.logger = logging.getLogger("Kubectl") + def get_configuration(self): + return config.kube_config.Configuration() + def get_services(self, field_selector=None, label_selector=None): kwargs = {} if field_selector: @@ -46,7 +49,9 @@ class Kubectl: "target_port": p.target_port, } for p in i.spec.ports - ], + ] + if i.spec.ports + else [], "external_ip": [i.ip for i in i.status.load_balancer.ingress] if i.status.load_balancer.ingress else None, @@ -56,3 +61,34 @@ class Kubectl: except ApiException as e: self.logger.error("Error calling get services: {}".format(e)) raise e + + def get_default_storage_class(self) -> str: + """ + Default storage class + + :return: Returns the default storage class name, if exists. + If not, it returns the first storage class. + If there are not storage classes, returns None + """ + + storagev1 = client.StorageV1Api() + storage_classes = storagev1.list_storage_class() + selected_sc = None + default_sc_annotations = { + "storageclass.kubernetes.io/is-default-class": "true", + # Older clusters still use the beta annotation. + "storageclass.beta.kubernetes.io/is-default-class": "true", + } + for sc in storage_classes.items: + if not selected_sc: + # Select the first storage class in case there is no a default-class + selected_sc = sc.metadata.name + annotations = sc.metadata.annotations + if any( + k in annotations and annotations[k] == v + for k, v in default_sc_annotations.items() + ): + # Default storage + selected_sc = sc.metadata.name + break + return selected_sc