// CmdDeploy implements the 'deploy' command func CmdDeploy(c *cli.Context) { utils.CheckRequiredFlags(c, []string{"kubeware"}) var kubeware string var localKubePath string var err error kubeware = os.Getenv("KDEPLOY_KUBEWARE") localKubePath, err = fetchers.Fetch(kubeware) if err != nil { log.Fatal(fmt.Errorf("Could not fetch kubeware: '%s' (%v)", kubeware, err)) } log.Debugf("Going to parse kubeware in %s", localKubePath) metadata := template.ParseMetadata(localKubePath) defaults, err := metadata.AttributeDefaults() utils.CheckError(err) // build attributes merging "role list" to defaults log.Debugf("Building attributes") attributes := template.BuildAttributes(c.String("attribute"), defaults) // get list of services and parse each one log.Debugf("Parsing services") servicesSpecs, err := metadata.ParseServices(attributes) utils.CheckError(err) // get list of replica controllers and parse each one log.Debugf("Parsing controllers") controllersSpecs, err := metadata.ParseControllers(attributes) utils.CheckError(err) // creates Kubernetes client kubernetes, err := webservice.NewKubeClient() utils.CheckError(err) // check if kubeware already exists log.Debugf("Checking if already deployed") deployedVersion, err := kubernetes.FindDeployedKubewareVersion(os.Getenv("KDEPLOY_NAMESPACE"), metadata.Name) utils.CheckError(err) if deployedVersion != "" { log.Errorf("Can not deploy '%s' since version '%s' is already deployed", metadata.Name, deployedVersion) return } // create each of the services log.Debugf("Creating services") err = kubernetes.CreateServices(utils.Values(servicesSpecs)) utils.CheckError(err) // create each of the controllers log.Debugf("Creating controllers") err = kubernetes.CreateReplicaControllers(utils.Values(controllersSpecs)) utils.CheckError(err) log.Infof("Kubeware %s from %s has been deployed", metadata.Name, os.Getenv("KDEPLOY_KUBEWARE")) }
func (rst *recreateAll) Upgrade(namespace string, services map[string]string, controllers map[string]string) error { svcNames := utils.Keys(services) rcNames := utils.Keys(controllers) // delete all delStrategy := deletionStrategies.WaitZeroReplicasDeletionStrategy(rst.kubeClient) err := delStrategy.Delete(namespace, svcNames, rcNames) if err != nil { return err } // recreate all err = rst.kubeClient.CreateServices(utils.Values(services)) if err != nil { return err } err = rst.kubeClient.CreateReplicaControllers(utils.Values(controllers)) if err != nil { return err } // done ! return nil }