Commit 0fcd7fcc authored by Michelle Noorali's avatar Michelle Noorali Committed by migmartri-michelleN

feat(tiller): add upgrade validations to tiller

parent 5e654c03
......@@ -70,12 +70,15 @@ func runUpgrade(cmd *cobra.Command, args []string) error {
return err
}
_, err = helm.UpdateRelease(args[0], chartPath, rawVals, upgradeDryRun)
res, err := helm.UpdateRelease(args[0], chartPath, rawVals, upgradeDryRun)
if err != nil {
return prettyError(err)
}
fmt.Println("Coming SOON to a Helm near YOU!")
newVersion := res.GetRelease().Version
fmt.Printf("I know you want to upgrade your release to version %v.\nHang tight. We're still working on the helm upgrade command.", newVersion)
fmt.Println("\nComing soon to a Helm near YOU!")
return nil
}
......@@ -174,7 +174,54 @@ func (s *releaseServer) GetReleaseContent(c ctx.Context, req *services.GetReleas
}
func (s *releaseServer) UpdateRelease(c ctx.Context, req *services.UpdateReleaseRequest) (*services.UpdateReleaseResponse, error) {
return nil, errNotImplemented
rel, err := s.prepareUpdate(req)
if err != nil {
return nil, err
}
// TODO: perform update
return &services.UpdateReleaseResponse{Release: rel}, nil
}
// prepareUpdate builds a release for an update operation.
func (s *releaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*release.Release, error) {
if req.Name == "" {
return nil, errMissingRelease
}
if req.Chart == nil {
return nil, errMissingChart
}
// finds the non-deleted release with the given name
rel, err := s.env.Releases.Read(req.Name)
if err != nil {
return nil, err
}
//validate chart name is same as previous release
givenChart := req.Chart.Metadata.Name
releasedChart := rel.Chart.Metadata.Name
if givenChart != releasedChart {
return nil, fmt.Errorf("Given chart, %s, does not match chart originally released, %s", givenChart, releasedChart)
}
// validate new chart version is higher than old
givenChartVersion := req.Chart.Metadata.Version
releasedChartVersion := rel.Chart.Metadata.Version
if givenChartVersion <= releasedChartVersion {
return nil, fmt.Errorf("Given chart (%s-%v) must be a higher version than released chart (%s-%v)", givenChart, givenChartVersion, releasedChart, releasedChartVersion)
}
// Store an updated release.
updatedRelease := &release.Release{
Name: req.Name,
Chart: req.Chart,
Config: req.Values,
Version: rel.Version + 1,
}
return updatedRelease, nil
}
func (s *releaseServer) uniqName(start string) (string, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment