Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Jul 23, 2024
1 parent 3622b7d commit 61d61be
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/buildtools/openebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func updateOpenEBSAddonImages(ctx context.Context, chartURL string, chartVersion
return fmt.Errorf("failed to get openebs values: %v", err)
}

logrus.Infof("extracting images from chart")
logrus.Infof("extracting images from chart version %s", chartVersion)
images, err := GetImagesFromOCIChart(chartURL, "openebs", chartVersion, values)
if err != nil {
return fmt.Errorf("failed to get images from admin console chart: %w", err)
Expand Down
32 changes: 32 additions & 0 deletions cmd/buildtools/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,38 @@ func GetLatestGitHubTag(ctx context.Context, owner, repo string) (string, error)
return tags[0].GetName(), nil
}

func GetBestGitHubTag(ctx context.Context, owner, repo string, constrants *semver.Constraints) (string, error) {
client := github.NewClient(nil)
tags, _, err := client.Repositories.ListTags(ctx, owner, repo, &github.ListOptions{})
if err != nil {
return "", fmt.Errorf("unable to list tags: %w", err)
}
var best *semver.Version
var bestStr string
for _, tag := range tags {
ver := tag.GetName()
ver = strings.TrimPrefix(ver, "v")
sv, err := semver.NewVersion(ver)
if err != nil {
continue
}
if sv.Prerelease() != "" {
continue
}
if !constrants.Check(sv) {
continue
}
if best == nil || sv.GreaterThan(best) {
best = sv
bestStr = tag.GetName()
}
}
if best == nil {
return "", fmt.Errorf("no tags found")
}
return bestStr, nil
}

func GetMakefileVariable(name string) (string, error) {
f, err := os.Open("./Makefile")
if err != nil {
Expand Down
43 changes: 35 additions & 8 deletions cmd/buildtools/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import (
"github.com/urfave/cli/v2"
)

// From: https://github.com/vmware-tanzu/velero-plugin-for-aws/blob/26bf6253ff0d74f8e5ce6aeb3053f31b7a297a99/README.md#compatibility
var veleroPluginForAWSCompatibility = map[string]*semver.Constraints{
"1.14": mustParseSemverConstraints(">=1.10,<1.11"),
"1.13": mustParseSemverConstraints(">=1.9,<1.10"),
}

var veleroImageComponents = map[string]string{
"docker.io/velero/velero": "velero",
"docker.io/velero/velero-plugin-for-aws": "velero-plugin-for-aws",
Expand Down Expand Up @@ -76,17 +82,18 @@ var updateVeleroAddonCommand = &cli.Command{
upstream := fmt.Sprintf("%s/velero", os.Getenv("CHARTS_DESTINATION"))
withproto := fmt.Sprintf("oci://proxy.replicated.com/anonymous/%s", upstream)

restoreHelperVersion, err := findVeleroVersionFromChart(c.Context, withproto, nextChartVersion)
veleroVersion, err := findVeleroVersionFromChart(c.Context, withproto, nextChartVersion)
if err != nil {
return fmt.Errorf("failed to find restore helper version: %w", err)
return fmt.Errorf("failed to find velero version from chart: %w", err)
}
restoreHelperVersion := veleroVersion
logrus.Infof("found latest velero restore helper version %s", restoreHelperVersion)

awsPluginVersion, err := findLatestAWSPluginVersion(c.Context)
awsPluginVersion, err := findBestAWSPluginVersion(c.Context, veleroVersion)
if err != nil {
return fmt.Errorf("failed to find latest velero plugin for aws version: %w", err)
}
logrus.Infof("found latest velero plugin for aws version %s", awsPluginVersion)
logrus.Infof("found best velero plugin for aws version %s", awsPluginVersion)

logrus.Infof("updating velero images")

Expand Down Expand Up @@ -156,10 +163,22 @@ func findVeleroVersionFromChart(ctx context.Context, chartURL string, chartVersi
return "", fmt.Errorf("failed to find velero image tag")
}

func findLatestAWSPluginVersion(ctx context.Context) (string, error) {
awsPluginVersion, err := GetLatestGitHubTag(ctx, "vmware-tanzu", "velero-plugin-for-aws")
func findBestAWSPluginVersion(ctx context.Context, veleroVersion string) (string, error) {
sv, err := semver.NewVersion(veleroVersion)
if err != nil {
return "", fmt.Errorf("failed to get latest velero plugin for aws release: %w", err)
return "", fmt.Errorf("failed to parse velero version: %w", err)
}
constraints, ok := veleroPluginForAWSCompatibility[fmt.Sprintf("%d.%d", sv.Major(), sv.Minor())]
if !ok {
awsPluginVersion, err := GetLatestGitHubTag(ctx, "vmware-tanzu", "velero-plugin-for-aws")
if err != nil {
return "", fmt.Errorf("failed to get latest velero plugin for aws release: %w", err)
}
return strings.TrimPrefix(awsPluginVersion, "v"), nil
}
awsPluginVersion, err := GetBestGitHubTag(ctx, "vmware-tanzu", "velero-plugin-for-aws", constraints)
if err != nil {
return "", fmt.Errorf("failed to get best velero plugin for aws release with constraints %s: %w", constraints, err)
}
return strings.TrimPrefix(awsPluginVersion, "v"), nil
}
Expand Down Expand Up @@ -192,7 +211,7 @@ func updateVeleroAddonImages(ctx context.Context, chartURL string, chartVersion
return fmt.Errorf("failed to get velero values: %v", err)
}

logrus.Infof("extracting images from chart")
logrus.Infof("extracting images from chart version %s", chartVersion)
images, err := GetImagesFromOCIChart(chartURL, "velero", chartVersion, values)
if err != nil {
return fmt.Errorf("failed to get images from admin console chart: %w", err)
Expand Down Expand Up @@ -257,3 +276,11 @@ func updateVeleroAddonImages(ctx context.Context, chartURL string, chartVersion

return nil
}

func mustParseSemverConstraints(s string) *semver.Constraints {
c, err := semver.NewConstraint(s)
if err != nil {
panic(err)
}
return c
}
2 changes: 1 addition & 1 deletion pkg/addons/velero/static/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ location: oci://proxy.replicated.com/anonymous/registry.replicated.com/ec-charts
images:
kubectl: 1.29.5-r0@sha256:6685cee257798285ad1ec15f3e85cd4524bdf62b0a7b3ee981e193da922e2426
velero: 1.13.2@sha256:9584eb07473d0fe8ccd8c9daa6f04efcd382df37d3cb09fd1ec0c5600c6e8343
velero-plugin-for-aws: 1.10.0@sha256:87a22849b30633427bbd5a41acca3faf17a676d6037d38106f6d0154f514ae0c
velero-plugin-for-aws: 1.9.2@sha256:9654091c85799c7e82c3f00b6c2d2895b28026451b1b2da5ddb365d1cdcdef09
velero-restore-helper: 1.13.2@sha256:5c3e0f294da2cb1481234da761c8ded62ec9bf816dfaff83cd2b869954bd2e79
6 changes: 3 additions & 3 deletions pkg/addons/velero/static/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ image:
repository: proxy.replicated.com/anonymous/replicated/ec-velero
tag: '1.13.2@sha256:9584eb07473d0fe8ccd8c9daa6f04efcd382df37d3cb09fd1ec0c5600c6e8343'
initContainers:
- image: 'proxy.replicated.com/anonymous/velero/velero-plugin-for-aws:v1.10.0@sha256:0b4fe36bbd5c7e484750bf21e25274cecbb72b30b097a72dc3e599430590bdfc'
- image: 'proxy.replicated.com/anonymous/replicated/ec-velero-plugin-for-aws:1.9.2@sha256:9654091c85799c7e82c3f00b6c2d2895b28026451b1b2da5ddb365d1cdcdef09'
imagePullPolicy: IfNotPresent
name: velero-plugin-for-aws
volumeMounts:
- mountPath: /target
name: plugins
kubectl:
image:
repository: proxy.replicated.com/anonymous/bitnami/kubectl
tag: '1.29@sha256:89bde5352cd988ed9440ff0956a7ceb00415923aea9d34fc0ac82d9b3eee8af7'
repository: proxy.replicated.com/anonymous/replicated/ec-kubectl
tag: '1.29.5-r0@sha256:6685cee257798285ad1ec15f3e85cd4524bdf62b0a7b3ee981e193da922e2426'
configMaps:
fs-restore-action-config:
labels:
Expand Down

0 comments on commit 61d61be

Please sign in to comment.