Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node build: Extract version from remote URL #3800

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions pkg/build/nodeimage/internal/kube/builder_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"time"

"sigs.k8s.io/kind/pkg/log"
)

var versionRE = regexp.MustCompile(`^v\d+\.\d+\.\d+`)

type remoteBuilder struct {
version string
logger log.Logger
Expand All @@ -40,8 +43,22 @@ var _ Builder = &remoteBuilder{}

// NewURLBuilder used to specify a complete url to a gzipped tarball
func NewURLBuilder(logger log.Logger, url string) (Builder, error) {
// Try to parse the version from the URL as one possible way to capture what
// we are building.
// If building a typical community published tarball, the URL will be in the
// format of https://dl.k8s.io/v1.30.0/kubernetes-server-linux-amd64.tar.gz
version := ""

parts := strings.Split(url, "/")
for _, part := range parts {
if versionRE.Match([]byte(part)) {
version = part
break
}
}

return &remoteBuilder{
version: "",
version: version,
logger: logger,
url: url,
}, nil
Expand Down Expand Up @@ -77,11 +94,18 @@ func (b *remoteBuilder) Build() (Bits, error) {
}

binDir := filepath.Join(tmpDir, "kubernetes/server/bin")

// See if we can get an exact version, but default to the version specified
sourceVersionRaw := b.version
contents, err := os.ReadFile(filepath.Join(tmpDir, "kubernetes/version"))
if err != nil {
if err == nil {
sourceVersionRaw = strings.TrimSpace(string(contents))
}

if err != nil && sourceVersionRaw == "" {
return nil, err
}
sourceVersionRaw := strings.TrimSpace(string(contents))

return &bits{
binaryPaths: []string{
filepath.Join(binDir, "kubeadm"),
Expand Down
Loading