Exemplo n.º 1
0
//deletePod removes the kubernetes pod
func (p *Kubernetes) deletePod(artifactPath string) error {
	if !utils.PathExists(artifactPath) {
		logrus.Errorf("No valid artifact could be found at %s", artifactPath)
		return errors.New("Path does not exist")
	}
	namespaceFlag := fmt.Sprintf("--namespace=%s", p.Namespace)
	deleteCmd := exec.Command(p.KubeCtl, "delete", "-f", artifactPath, namespaceFlag)

	//In a dry run, we don't actually execute the commands, so we log and return here
	if p.DryRun() {
		logrus.Infof("DRY RUN: %s\n", deleteCmd.Args)
		return nil
	}

	if _, err := utils.CheckCommandOutput(deleteCmd, false); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 2
0
//Issues a command to kubectl.
//Path is the path of the kubernets file to pass to kubectl
func (p *Kubernetes) kubectlCmd(path string) error {
	if p.Namespace == "" {
		p.Namespace = constants.DEFAULT_NAMESPACE
	}
	path = utils.SanitizePath(path)
	namespaceFlag := fmt.Sprintf("--namespace=%s", p.Namespace)
	kubeCmd := exec.Command(p.KubeCtl, "create", "-f", path, namespaceFlag)

	//In a dry run, we don't actually execute the commands, so we log and return here
	if p.DryRun() {
		logrus.Infof("DRY RUN: %s\n", kubeCmd.Args)
		return nil
	}

	if _, err := utils.CheckCommandOutput(kubeCmd, false); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 3
0
//Resets the replication controller with the given name
func (p *Kubernetes) resetReplica(name string) error {
	if name == "" {
		logrus.Errorf("No pod name provided in call to reset replication controller.")
		return errors.New("No pod name provided")
	}
	namespaceFlag := fmt.Sprintf("--namespace=%s", p.Namespace)
	resizeCmd := exec.Command(p.KubeCtl, "resize", "rc", name, "--replicas=0", namespaceFlag)

	//In a dry run, we don't actually execute the commands, so we log and return here
	if p.DryRun() {
		logrus.Infof("DRY RUN: %s\n", resizeCmd.Args)
		return nil
	}

	if _, err := utils.CheckCommandOutput(resizeCmd, false); err != nil {
		logrus.Errorf("Error reseting kubernetes replication controller")
		return err
	}
	return nil
}