in custom-targets/helm/helm-deployer/deploy.go [72:123]
func (d *deployer) deploy(ctx context.Context) (*clouddeploy.DeployResult, error) {
fmt.Printf("Downloading helm configuration archive to %s\n", srcArchivePath)
inURI, err := d.req.DownloadInput(ctx, d.gcsClient, renderedArchiveName, srcArchivePath)
if err != nil {
return nil, fmt.Errorf("unable to download deploy input with object suffix %s: %v", renderedArchiveName, err)
}
fmt.Printf("Downloaded helm configuration archive from %s\n", inURI)
archiveFile, err := os.Open(srcArchivePath)
if err != nil {
return nil, fmt.Errorf("unable to open archive file %s: %v", srcArchivePath, err)
}
fmt.Printf("Unarchiving helm configuration in %s to %s\n", srcArchivePath, srcPath)
if err := archiver.NewTarGz().Unarchive(archiveFile.Name(), srcPath); err != nil {
return nil, fmt.Errorf("unable to unarchive helm configuration: %v", err)
}
fmt.Printf("Setting up cluster credentials for %s\n", d.params.gkeCluster)
if _, err := gcloudClusterCredentials(d.params.gkeCluster); err != nil {
return nil, fmt.Errorf("unable to set up cluster credentials: %v", err)
}
fmt.Printf("Finished setting up cluster credentials for %s\n", d.params.gkeCluster)
// Use the pipeline ID as the helm release since this should be consistent.
helmRelease := d.req.Pipeline
chartPath := determineChartPath(d.params)
hOpts := helmOptions{namespace: d.params.namespace}
if _, err := helmUpgrade(helmRelease, chartPath, &helmUpgradeOptions{helmOptions: hOpts, timeout: d.params.upgradeTimeout}); err != nil {
return nil, fmt.Errorf("error running helm upgrade: %v", err)
}
// After `helm upgrade` succeeds get the manifest to upload as the deploy artifact.
manifest, err := helmGetManifest(helmRelease, &helmOptions{namespace: d.params.namespace})
if err != nil {
return nil, fmt.Errorf("error running helm get manifest aft upgrade: %v", err)
}
fmt.Println("Uploading helm release manifest as a deploy artifact")
mURI, err := d.req.UploadArtifact(ctx, d.gcsClient, "manifest.yaml", &clouddeploy.GCSUploadContent{Data: manifest})
if err != nil {
return nil, fmt.Errorf("error uploading helm release manifest deploy artifact: %v", err)
}
dr := &clouddeploy.DeployResult{
ResultStatus: clouddeploy.DeploySucceeded,
ArtifactFiles: []string{mURI},
Metadata: map[string]string{
clouddeploy.CustomTargetSourceMetadataKey: helmDeployerSampleName,
clouddeploy.CustomTargetSourceSHAMetadataKey: clouddeploy.GitCommit,
},
}
return dr, nil
}