Exemple #1
0
 def _setupDockerRepo(self):
     uLogging.info('Setup Docker repository host: %s' %
                   self.k8s_docker_repo_host)
     self._setSystemProperty('kubernetes_docker_repository_host',
                             self.k8s_docker_repo_host)
     command = self._K8S.get_image_pull_secrets_patch_cmd()
     uUtil.readCmd(command)
Exemple #2
0
 def _get_master_location(self):
     command = [
         'kubectl', 'config', 'view', '--minify=true', '--output=json'
     ]
     url = json.loads(uUtil.readCmd(command)).get('clusters', [{}])[0].get(
         'cluster', {}).get('server', '')
     return urlparse(url).hostname or ''
Exemple #3
0
 def _loadsLatestCharts(self, repoName):
     command = '%s search %s/' % (self._getHelmCommand(), repoName)
     uLogging.info('Loads latest charts: %s' % command)
     charts = list(
         csv.reader(StringIO(uUtil.readCmd(command)), delimiter='\t'))
     charts = [list(map(str.strip, x)) for x in charts]
     charts[0] = list(map(lambda x: x.title().replace(' ', ''), charts[0]))
     return list(map(lambda x: dict(zip(charts[0], x)), charts[1:]))
Exemple #4
0
 def _upgradeHelmPackage(self, pkg, reuse_values_file_path):
     command = '%s upgrade %s %s --wait' % (self._getHelmCommand(),
                                            pkg.name, pkg.chart)
     if pkg.group and (pkg.group == HelmGroup.FOUNDATION
                       or pkg.group == HelmGroup.REQUIRED):
         command = '%s --install' % command
     if pkg.version and pkg.version != 'latest':
         command = '%s --version %s' % (command, pkg.version)
     command = '%s -f %s' % (command, reuse_values_file_path)
     dockerRepo = self._getKubernetesDockerRepositoryHost()
     if dockerRepo:
         command = '%s --set dockerrepo=%s' % (command, dockerRepo)
     with tempfile.NamedTemporaryFile() as values_file:
         command = '%s -f %s' % (command, values_file.name)
         self._fillHelmPackageValuesFile(pkg, values_file)
         uLogging.info('Upgrade Helm package: %s (%s)' %
                       (command, pkg.script))
         uUtil.readCmd(command)
     return command
Exemple #5
0
 def _updateHelmRepo(self):
     command = ' %s repo update' % self._getHelmCommand()
     uLogging.info('Update Helm repository: %s' % command)
     uUtil.readCmd(command)
Exemple #6
0
 def _loadsDeployedReleases(self):
     command = '%s list --output json' % self._getHelmCommand()
     uLogging.info('Loads deployed releases: %s' % command)
     output = uUtil.readCmd(command)
     if not output: output = '{}'
     return json.loads(output).get('Releases', [])
Exemple #7
0
 def _isHelmUpgradeServerRequired(self):
     command = '%s version --server --template {{.Server.SemVer}}' % self._getHelmCommand(
     )
     version = uUtil.readCmd(command)
     return uBuild.compare_versions(self.getTargetHelmVersion(),
                                    version) > 0
Exemple #8
0
 def _setupK8sApiToken(self):
     token = uUtil.readCmd(
         "kubectl get secret -n kube-system $(kubectl get secrets -n kube-system | grep tiller | cut -f1 -d ' ') -o jsonpath={.data.token} | base64 -d"
     )
     self._setSystemProperty('kubernetes_token', token)
Exemple #9
0
 def _setupK8sApiUrl(self):
     api_url = uUtil.readCmd(
         'kubectl config view -o jsonpath="{.clusters[*].cluster.server}"')
     uLogging.info('Setup Kubernetes API URL: %s' % api_url)
     self._setSystemProperty('kubernetes_api', api_url)
Exemple #10
0
 def getChartDeployments(chart_name):
     output = uUtil.readCmd(
         "kubectl get deployment --no-headers -l release=%s -o json" %
         chart_name)
     if not output: output = '{}'
     return json.loads(output)
Exemple #11
0
 def _setupHelmRepo(self, version):
     repo = uK8s.Repo(prefix=self.k8s_repo_url)
     repo_url = repo.custom_url(version)
     uLogging.info('Setup Helm repository: %s' % repo_url)
     command = self._K8S.get_custom_helm_repo_add_cmd(repo, version)
     uUtil.readCmd(command)
Exemple #12
0
 def _upgradeHelmRepo(self, version):
     uLogging.info('Upgrade Helm repository to version: %s' % version)
     repo = self._K8S.get_helm_repo()
     if not repo.is_upgradable_url(): return
     command = self._K8S.get_custom_helm_repo_add_cmd(repo, version)
     uUtil.readCmd(command)
Exemple #13
0
 def getReadyNodes():
     return uUtil.readCmd(
         "kubectl get node --no-headers  | grep Ready | awk '{print $1}'")
Exemple #14
0
 def _dumpPackageValues(self, pkg, reuse_values_file_path):
     command = '%s get values --all %s > %s' % (
         self._getHelmCommand(), pkg.name, reuse_values_file_path)
     uUtil.readCmd(command, valid_codes=[0, 1])
     return command
Exemple #15
0
def get_nodes_capacity():
    return uUtil.readCmd(
        "kubectl describe node | grep Capacity: -A 7 | grep -P 'cpu|memory' | awk '{print $2}'"
    ).splitlines()
Exemple #16
0
def get_nodes_allocated_resources():
    return uUtil.readCmd(
        "kubectl describe node | grep Allocated -A 5 | grep -P 'cpu|memory' | awk '{print $3}' | sed -e 's/[^0-9]//g'"
    ).splitlines()
Exemple #17
0
 def getPendingPods():
     return uUtil.readCmd(
         "kubectl get pod | grep Pending | awk '{print $1}'")
Exemple #18
0
 def getChartStatefulSet(chart_name):
     output = uUtil.readCmd(
         "kubectl get StatefulSet --no-headers -l release=%s -o json" %
         chart_name)
     if not output: output = '{}'
     return json.loads(output)