Skip to content

Commit ef87397

Browse files
authored
Merge pull request #17306 from spowelljr/autoUpdateIstioOperator
CI: Auto update istio/operator image
2 parents 02c0db5 + def9996 commit ef87397

File tree

5 files changed

+127
-37
lines changed

5 files changed

+127
-37
lines changed

Diff for: .github/workflows/update-istio-operator.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: "update-istio-operator-version"
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
# every Monday at around 3 am pacific/10 am UTC
6+
- cron: "0 10 * * 1"
7+
env:
8+
GOPROXY: https://proxy.golang.org
9+
GO_VERSION: '1.21.1'
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
bump-istio-operator-version:
15+
runs-on: ubuntu-20.04
16+
steps:
17+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
18+
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe
19+
with:
20+
go-version: ${{env.GO_VERSION}}
21+
cache-dependency-path: ./go.sum
22+
- name: Bump istio-operator version
23+
id: bumpIstioOperator
24+
run: |
25+
echo "OLD_VERSION=$(DEP=istio-operator make get-dependency-version)" >> $GITHUB_OUTPUT
26+
make update-istio-operator-version
27+
echo "NEW_VERSION=$(DEP=istio-operator make get-dependency-version)" >> $GITHUB_OUTPUT
28+
# The following is to support multiline with GITHUB_OUTPUT, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
29+
echo "changes<<EOF" >> $GITHUB_OUTPUT
30+
echo "$(git status --porcelain)" >> $GITHUB_OUTPUT
31+
echo "EOF" >> $GITHUB_OUTPUT
32+
- name: Create PR
33+
if: ${{ steps.bumpIstioOperator.outputs.changes != '' }}
34+
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38
35+
with:
36+
token: ${{ secrets.MINIKUBE_BOT_PAT }}
37+
commit-message: 'Addon istio-provisioner: Update istio/operator image from ${{ steps.bumpIstioOperator.outputs.OLD_VERSION }} to ${{ steps.bumpIstioOperator.outputs.NEW_VERSION }}'
38+
committer: minikube-bot <[email protected]>
39+
author: minikube-bot <[email protected]>
40+
branch: auto_bump_istio_operator_version
41+
push-to-fork: minikube-bot/minikube
42+
base: master
43+
delete-branch: true
44+
title: 'Addon istio-provisioner: Update istio/operator image from ${{ steps.bumpIstioOperator.outputs.OLD_VERSION }} to ${{ steps.bumpIstioOperator.outputs.NEW_VERSION }}'
45+
labels: ok-to-test
46+
body: |
47+
The [istio](https://github.com/istio/istio) project released a new istio/operator image
48+
49+
This PR was auto-generated by `make update-istio-operator-version` using [update-istio-operator-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-istio-operator-version.yml) CI Workflow.

Diff for: Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,11 @@ update-kindnetd-version:
11701170
(cd hack/update/kindnetd_version && \
11711171
go run update_kindnetd_version.go)
11721172

1173+
.PHONY: update-istio-operator-version
1174+
update-istio-operator-version:
1175+
(cd hack/update/istio_operator_version && \
1176+
go run update_istio_operator_version.go)
1177+
11731178
.PHONY: get-dependency-verison
11741179
get-dependency-version:
11751180
@(cd hack/update/get_version && \

Diff for: hack/update/get_version/get_version.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var dependencies = map[string]dependency{
5050
"hugo": {"netlify.toml", `HUGO_VERSION = "(.*)"`},
5151
"ingress": {addonsFile, `ingress-nginx/controller:(.*)@`},
5252
"inspektor-gadget": {addonsFile, `inspektor-gadget/inspektor-gadget:(.*)@`},
53+
"istio-operator": {addonsFile, `istio/operator:(.*)@`},
5354
"kindnetd": {"pkg/minikube/bootstrapper/images/images.go", `kindnetd:(.*)"`},
5455
"metrics-server": {addonsFile, `metrics-server/metrics-server:(.*)@`},
5556
"nerdctl": {"deploy/kicbase/Dockerfile", `NERDCTL_VERSION="(.*)"`},

Diff for: hack/update/github.go

+13-37
Original file line numberDiff line numberDiff line change
@@ -48,80 +48,56 @@ func GHReleases(ctx context.Context, owner, repo string) (stable, latest, edge R
4848
// walk through the paginated list of up to ghSearchLimit newest releases
4949
opts := &github.ListOptions{PerPage: ghListPerPage}
5050
for (opts.Page+1)*ghListPerPage <= ghSearchLimit {
51-
rls, resp, err := ghc.Repositories.ListReleases(ctx, owner, repo, opts)
51+
rls, resp, err := ghc.Repositories.ListTags(ctx, owner, repo, opts)
5252
if err != nil {
5353
return stable, latest, edge, err
5454
}
5555
for _, rl := range rls {
56-
ver := rl.GetTagName()
56+
ver := rl.GetName()
57+
commit := rl.GetCommit().GetSHA()
5758
if !semver.IsValid(ver) {
58-
continue
59+
ver = fmt.Sprintf("v%s", ver)
60+
if !semver.IsValid(ver) {
61+
continue
62+
}
5963
}
6064
// check if ver version is release (ie, 'v1.19.2') or pre-release (ie, 'v1.19.3-rc.0' or 'v1.19.0-beta.2')
6165
prerls := semver.Prerelease(ver)
6266
if prerls == "" {
6367
if semver.Compare(ver, stable.Tag) == 1 {
6468
stable.Tag = ver
69+
stable.Commit = commit
6570
}
6671
} else if strings.HasPrefix(prerls, "-rc") || strings.HasPrefix(prerls, "-beta") {
6772
if semver.Compare(ver, latest.Tag) == 1 {
6873
latest.Tag = ver
74+
latest.Commit = commit
6975
}
7076
} else if strings.Contains(prerls, "-alpha") {
7177
if semver.Compare(ver, edge.Tag) == 1 {
7278
edge.Tag = ver
79+
edge.Commit = commit
7380
}
7481
}
7582

7683
// make sure that latest >= stable
7784
if semver.Compare(latest.Tag, stable.Tag) == -1 {
7885
latest.Tag = stable.Tag
86+
latest.Commit = stable.Commit
7987
}
8088
// make sure that edge >= latest
8189
if semver.Compare(edge.Tag, latest.Tag) == -1 {
8290
edge.Tag = latest.Tag
91+
edge.Commit = latest.Commit
8392
}
8493
}
8594
if resp.NextPage == 0 {
8695
break
8796
}
8897
opts.Page = resp.NextPage
8998
}
90-
// create a map where the key is the tag and the values is an array of releases (stable, latest, edge) that match the tag
91-
releasesWithoutCommits := map[string][]*Release{}
92-
for _, rl := range []*Release{&stable, &latest, &edge} {
93-
releasesWithoutCommits[rl.Tag] = append(releasesWithoutCommits[rl.Tag], rl)
94-
}
95-
// run though the releases to find ones that don't yet have a commit and assign it
96-
opts = &github.ListOptions{PerPage: ghListPerPage}
97-
for (opts.Page+1)*ghListPerPage <= ghSearchLimit {
98-
tags, resp, err := ghc.Repositories.ListTags(ctx, owner, repo, opts)
99-
if err != nil {
100-
return stable, latest, edge, err
101-
}
102-
for _, tag := range tags {
103-
rls, ok := releasesWithoutCommits[*tag.Name]
104-
if !ok {
105-
continue
106-
}
107-
for _, rl := range rls {
108-
rl.Commit = *tag.Commit.SHA
109-
}
110-
delete(releasesWithoutCommits, *tag.Name)
111-
if len(releasesWithoutCommits) == 0 {
112-
return stable, latest, edge, nil
113-
}
114-
}
115-
if len(releasesWithoutCommits) == 0 {
116-
break
117-
}
118-
if resp.NextPage == 0 {
119-
break
120-
}
121-
opts.Page = resp.NextPage
122-
}
12399

124-
return stable, latest, edge, fmt.Errorf("wasn't able to find commit for releases")
100+
return stable, latest, edge, nil
125101
}
126102

127103
func StableVersion(ctx context.Context, owner, repo string) (string, error) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"strings"
23+
"time"
24+
25+
"k8s.io/klog/v2"
26+
"k8s.io/minikube/hack/update"
27+
)
28+
29+
var schema = map[string]update.Item{
30+
"pkg/minikube/assets/addons.go": {
31+
Replace: map[string]string{
32+
`istio/operator:.*`: `istio/operator:{{.Version}}@{{.SHA}}",`,
33+
},
34+
},
35+
}
36+
37+
type Data struct {
38+
Version string
39+
SHA string
40+
}
41+
42+
func main() {
43+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
44+
defer cancel()
45+
46+
stable, _, _, err := update.GHReleases(ctx, "istio", "istio")
47+
if err != nil {
48+
klog.Fatalf("Unable to get stable version: %v", err)
49+
}
50+
version := strings.TrimPrefix(stable.Tag, "v")
51+
sha, err := update.GetImageSHA(fmt.Sprintf("docker.io/istio/operator:%s", version))
52+
if err != nil {
53+
klog.Fatalf("failed to get image SHA: %v", err)
54+
}
55+
56+
data := Data{Version: version, SHA: sha}
57+
58+
update.Apply(schema, data)
59+
}

0 commit comments

Comments
 (0)