Merge pull request #17904 from spowelljr/automateUpdatingKubectlImage
CI: Automate updating kubectl imagepull/17830/head
commit
8f736a32a1
|
@ -25,10 +25,9 @@ jobs:
|
|||
t=$(make update-kubernetes-version)
|
||||
t=$(echo $t | head -n 1)
|
||||
echo "title=$t" >> "$GITHUB_OUTPUT"
|
||||
c=$(git status --porcelain)
|
||||
# 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
|
||||
echo "changes<<EOF" >> "$GITHUB_OUTPUT"
|
||||
echo "$c" >> "$GITHUB_OUTPUT"
|
||||
echo "$(git status --porcelain)" >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
- name: Create PR
|
||||
if: ${{ steps.bumpk8s.outputs.changes != '' }}
|
||||
|
|
|
@ -29,7 +29,6 @@ jobs:
|
|||
echo "$c" >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
- name: Create PR
|
||||
id: createPR
|
||||
if: ${{ steps.bumpKindnetd.outputs.changes != '' }}
|
||||
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38
|
||||
with:
|
||||
|
|
|
@ -23,10 +23,9 @@ jobs:
|
|||
id: bumpKubeadmConsts
|
||||
run: |
|
||||
make update-kubeadm-constants
|
||||
c=$(git status --porcelain)
|
||||
# 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
|
||||
echo "changes<<EOF" >> "$GITHUB_OUTPUT"
|
||||
echo "$c" >> "$GITHUB_OUTPUT"
|
||||
echo "$(git status --porcelain)" >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
- name: Create PR
|
||||
if: ${{ steps.bumpKubeadmConsts.outputs.changes != '' }}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
name: "update-kubectl-version"
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# every Monday at around 3 am pacific/10 am UTC
|
||||
- cron: "0 10 * * 1"
|
||||
env:
|
||||
GOPROXY: https://proxy.golang.org
|
||||
GO_VERSION: '1.21.5'
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
bump-kubectl-version:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
|
||||
with:
|
||||
go-version: ${{env.GO_VERSION}}
|
||||
cache-dependency-path: ./go.sum
|
||||
- name: Bump Kubectl version
|
||||
id: bumpKubectl
|
||||
run: |
|
||||
echo "OLD_VERSION=$(DEP=kubectl make get-dependency-version)" >> "$GITHUB_OUTPUT"
|
||||
make update-kubectl-version
|
||||
echo "NEW_VERSION=$(DEP=kubectl make get-dependency-version)" >> "$GITHUB_OUTPUT"
|
||||
# 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
|
||||
echo "changes<<EOF" >> "$GITHUB_OUTPUT"
|
||||
echo "$(git status --porcelain)" >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
- name: Create PR
|
||||
if: ${{ steps.bumpKubectl.outputs.changes != '' }}
|
||||
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38
|
||||
with:
|
||||
token: ${{ secrets.MINIKUBE_BOT_PAT }}
|
||||
commit-message: 'Addon kubevirt: Update bitnami/kubectl image from ${{ steps.bumpKubectl.outputs.OLD_VERSION }} to ${{ steps.bumpKubectl.outputs.NEW_VERSION }}'
|
||||
committer: minikube-bot <minikube-bot@google.com>
|
||||
author: minikube-bot <minikube-bot@google.com>
|
||||
branch: auto_bump_kubectl_version
|
||||
push-to-fork: minikube-bot/minikube
|
||||
base: master
|
||||
delete-branch: true
|
||||
title: 'Addon kubevirt: Update bitnami/kubectl image from ${{ steps.bumpKubectl.outputs.OLD_VERSION }} to ${{ steps.bumpKubectl.outputs.NEW_VERSION }}'
|
||||
labels: ok-to-test
|
||||
body: |
|
||||
The [bitnami](https://github.com/bitnami/containers) project released a new bitnami/kubectl image
|
||||
|
||||
This PR was auto-generated by `make update-kubectl-version` using [update-kubectl-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-kubectl-version.yml) CI Workflow.
|
|
@ -25,9 +25,9 @@ jobs:
|
|||
echo "OLD_VERSION=$(DEP=ubuntu make get-dependency-version)" >> "$GITHUB_OUTPUT"
|
||||
make update-ubuntu-version
|
||||
echo "NEW_VERSION=$(DEP=ubuntu make get-dependency-version)" >> "$GITHUB_OUTPUT"
|
||||
c=$(git status --porcelain)
|
||||
# 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
|
||||
echo "changes<<EOF" >> "$GITHUB_OUTPUT"
|
||||
echo "$c" >> "$GITHUB_OUTPUT"
|
||||
echo "$(git status --porcelain)" >> "$GITHUB_OUTPUT"
|
||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||
- name: Create PR
|
||||
id: createPR
|
||||
|
|
5
Makefile
5
Makefile
|
@ -1200,6 +1200,11 @@ update-nerdctld-version:
|
|||
(cd hack/update/nerdctld_version && \
|
||||
go run update_nerdctld_version.go)
|
||||
|
||||
.PHONY: update-kubectl-version
|
||||
update-kubectl-version:
|
||||
(cd hack/update/kubectl_version && \
|
||||
go run update_kubectl_version.go)
|
||||
|
||||
.PHONY: get-dependency-verison
|
||||
get-dependency-version:
|
||||
@(cd hack/update/get_version && \
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
Copyright 2024 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package update
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const dockerHubTagsURL = "https://hub.docker.com/v2/repositories/%s/tags?page_size=100"
|
||||
|
||||
// Response is used to unmarshal the response from Docker Hub
|
||||
type Response struct {
|
||||
Results []struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
}
|
||||
|
||||
// ImageTagsFromDockerHub returns the 100 latest image tags from Docker Hub for the provided repository
|
||||
func ImageTagsFromDockerHub(repo string) ([]string, error) {
|
||||
resp, err := http.Get(fmt.Sprintf(dockerHubTagsURL, repo))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get tags list: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read HTTP response from Docker Hub: %v", err)
|
||||
}
|
||||
|
||||
var content Response
|
||||
err = json.Unmarshal(body, &content)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to unmarshal response from Docker Hub: %v", err)
|
||||
}
|
||||
|
||||
versions := make([]string, len(content.Results))
|
||||
for i, tag := range content.Results {
|
||||
versions[i] = tag.Name
|
||||
}
|
||||
|
||||
if len(versions) == 0 {
|
||||
return nil, fmt.Errorf("tag list is empty")
|
||||
}
|
||||
|
||||
return versions, nil
|
||||
}
|
|
@ -54,6 +54,7 @@ var dependencies = map[string]dependency{
|
|||
"kindnetd": {"pkg/minikube/bootstrapper/images/images.go", `kindnetd:(.*)"`},
|
||||
"kong": {addonsFile, `kong:(.*)@`},
|
||||
"kong-ingress-controller": {addonsFile, `kong/kubernetes-ingress-controller:(.*)@`},
|
||||
"kubectl": {addonsFile, `bitnami/kubectl:(.*)@`},
|
||||
"metrics-server": {addonsFile, `metrics-server/metrics-server:(.*)@`},
|
||||
"nerdctl": {"deploy/kicbase/Dockerfile", `NERDCTL_VERSION="(.*)"`},
|
||||
"nerdctld": {"deploy/kicbase/Dockerfile", `NERDCTLD_VERSION="(.*)"`},
|
||||
|
|
|
@ -17,20 +17,11 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/minikube/hack/update"
|
||||
)
|
||||
|
||||
const (
|
||||
dockerHubKindnetdTags = "https://hub.docker.com/v2/repositories/kindest/kindnetd/tags"
|
||||
)
|
||||
|
||||
var (
|
||||
schema = map[string]update.Item{
|
||||
"pkg/minikube/bootstrapper/images/images.go": {
|
||||
|
@ -45,43 +36,12 @@ type Data struct {
|
|||
LatestVersion string
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Results []struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
}
|
||||
|
||||
func getLatestVersion() (string, error) {
|
||||
resp, err := http.Get(dockerHubKindnetdTags)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get tags: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read HTTP response: %v", err)
|
||||
}
|
||||
|
||||
var content Response
|
||||
err = json.Unmarshal(body, &content)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to unmarshal response: %v", err)
|
||||
}
|
||||
|
||||
if len(content.Results) == 0 {
|
||||
return "", fmt.Errorf("tag list is empty")
|
||||
}
|
||||
|
||||
return content.Results[0].Name, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
latest, err := getLatestVersion()
|
||||
tags, err := update.ImageTagsFromDockerHub("kindest/kindnetd")
|
||||
if err != nil {
|
||||
klog.Fatalf("failed to get latest version: %v", err)
|
||||
klog.Fatal(err)
|
||||
}
|
||||
data := Data{LatestVersion: latest}
|
||||
data := Data{LatestVersion: tags[0]}
|
||||
|
||||
update.Apply(schema, data)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
Copyright 2024 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/minikube/hack/update"
|
||||
)
|
||||
|
||||
var schema = map[string]update.Item{
|
||||
"pkg/minikube/assets/addons.go": {
|
||||
Replace: map[string]string{
|
||||
`"bitnami/kubectl:.*`: `"bitnami/kubectl:{{.Version}}@{{.SHA}}",`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
Version string
|
||||
SHA string
|
||||
}
|
||||
|
||||
func main() {
|
||||
tags, err := update.ImageTagsFromDockerHub("bitnami/kubectl")
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
tag, err := latestStableSemverTag(tags)
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
sha, err := update.GetImageSHA(fmt.Sprintf("docker.io/bitnami/kubectl:%s", tag))
|
||||
if err != nil {
|
||||
klog.Fatalf("failed to get image SHA: %v", err)
|
||||
}
|
||||
|
||||
data := Data{Version: tag, SHA: sha}
|
||||
|
||||
update.Apply(schema, data)
|
||||
}
|
||||
|
||||
func latestStableSemverTag(tags []string) (string, error) {
|
||||
for _, tag := range tags {
|
||||
vTag := fmt.Sprintf("v%s", tag)
|
||||
if semver.IsValid(vTag) && semver.Prerelease(vTag) == "" {
|
||||
return tag, nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no stable semver tag found")
|
||||
}
|
|
@ -17,18 +17,13 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/minikube/hack/update"
|
||||
)
|
||||
|
||||
const dockerHubRegistryURL = "https://hub.docker.com/v2/repositories/library/registry/tags"
|
||||
|
||||
var schema = map[string]update.Item{
|
||||
"pkg/minikube/assets/addons.go": {
|
||||
Replace: map[string]string{
|
||||
|
@ -42,52 +37,31 @@ type Data struct {
|
|||
SHA string
|
||||
}
|
||||
|
||||
// Response is used to unmarshal the response from Docker Hub
|
||||
type Response struct {
|
||||
Results []struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
version, err := getLatestVersion()
|
||||
tags, err := update.ImageTagsFromDockerHub("library/registry")
|
||||
if err != nil {
|
||||
klog.Fatalf("failed to get latest version: %v", err)
|
||||
klog.Fatal(err)
|
||||
}
|
||||
version = strings.TrimPrefix(version, "v")
|
||||
sha, err := update.GetImageSHA(fmt.Sprintf("docker.io/registry:%s", version))
|
||||
tag, err := latestStableSemverTag(tags)
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
sha, err := update.GetImageSHA(fmt.Sprintf("docker.io/registry:%s", tag))
|
||||
if err != nil {
|
||||
klog.Fatalf("failed to get image SHA: %v", err)
|
||||
}
|
||||
|
||||
data := Data{Version: version, SHA: sha}
|
||||
data := Data{Version: tag, SHA: sha}
|
||||
|
||||
update.Apply(schema, data)
|
||||
}
|
||||
|
||||
func getLatestVersion() (string, error) {
|
||||
resp, err := http.Get(dockerHubRegistryURL)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get tags: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read response body: %v", err)
|
||||
}
|
||||
|
||||
var content Response
|
||||
err = json.Unmarshal(body, &content)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to unmarshal response: %v", err)
|
||||
}
|
||||
|
||||
for _, i := range content.Results {
|
||||
if !strings.Contains(i.Name, "latest") {
|
||||
return i.Name, nil
|
||||
func latestStableSemverTag(tags []string) (string, error) {
|
||||
for _, tag := range tags {
|
||||
vTag := fmt.Sprintf("v%s", tag)
|
||||
if semver.IsValid(vTag) && semver.Prerelease(vTag) == "" {
|
||||
return tag, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("didn't find a non-latest image")
|
||||
return "", fmt.Errorf("no stable semver tag found")
|
||||
}
|
||||
|
|
|
@ -17,10 +17,7 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
@ -28,10 +25,6 @@ import (
|
|||
"k8s.io/minikube/hack/update"
|
||||
)
|
||||
|
||||
const (
|
||||
dockerHubUbuntuBaseURL = "https://hub.docker.com/v2/repositories/library/ubuntu/tags"
|
||||
)
|
||||
|
||||
var (
|
||||
schema = map[string]update.Item{
|
||||
"deploy/kicbase/Dockerfile": {
|
||||
|
@ -47,48 +40,25 @@ type Data struct {
|
|||
LatestVersion string
|
||||
}
|
||||
|
||||
// Response is used to unmarshal the response from Docker Hub
|
||||
type Response struct {
|
||||
Results []struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
}
|
||||
|
||||
func getLatestVersion() (string, error) {
|
||||
resp, err := http.Get(dockerHubUbuntuBaseURL)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to get Ubuntu jammy's latest version: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to read HTTP response from Docker Hub: %v", err)
|
||||
}
|
||||
|
||||
var content Response
|
||||
err = json.Unmarshal(body, &content)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to unmarshal response from Docker Hub: %v", err)
|
||||
}
|
||||
|
||||
for _, i := range content.Results {
|
||||
if strings.Contains(i.Name, "jammy-") {
|
||||
return i.Name, nil
|
||||
func latestJammyTag(tags []string) (string, error) {
|
||||
for _, tag := range tags {
|
||||
if strings.Contains(tag, "jammy-") {
|
||||
return tag, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("response from Docker Hub does not contain a latest jammy image")
|
||||
return "", fmt.Errorf("no tag found that matches: jammy-")
|
||||
}
|
||||
|
||||
func main() {
|
||||
// get Ubuntu Jammy latest version
|
||||
latest, err := getLatestVersion()
|
||||
tags, err := update.ImageTagsFromDockerHub("library/ubuntu")
|
||||
if err != nil {
|
||||
klog.Fatalf("Unable to find latest ubuntu:jammy version: %v\n", err)
|
||||
klog.Fatal(err)
|
||||
}
|
||||
data := Data{LatestVersion: fmt.Sprintf("ubuntu:%s", latest)}
|
||||
klog.Infof("Ubuntu jammy latest version: %s", latest)
|
||||
jammyTag, err := latestJammyTag(tags)
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
data := Data{LatestVersion: fmt.Sprintf("ubuntu:%s", jammyTag)}
|
||||
|
||||
update.Apply(schema, data)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue