Skip to content

Commit

Permalink
feat(ec): ability to upgrade the cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Jun 26, 2024
1 parent 9b6034d commit 5aef836
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 47 deletions.
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,27 @@ debug: debug-build
LOG_LEVEL=$(LOG_LEVEL) dlv --listen=:2345 --headless=true --api-version=2 exec ./bin/kotsadm-debug api

.PHONY: build-ttl.sh
build-ttl.sh: export GOOS ?= linux
build-ttl.sh: export GOARCH ?= amd64
build-ttl.sh: kots build
source .image.env && ${MAKE} -C web build-kotsadm
docker build -f deploy/Dockerfile -t ttl.sh/${CURRENT_USER}/kotsadm:24h .
source .image.env && ${MAKE} -C web deps build-kotsadm
docker build --platform $(GOOS)/$(GOARCH) -f deploy/Dockerfile -t ttl.sh/${CURRENT_USER}/kotsadm:24h .
docker push ttl.sh/${CURRENT_USER}/kotsadm:24h

.PHONY: all-ttl.sh
all-ttl.sh: export GOOS ?= linux
all-ttl.sh: export GOARCH ?= amd64
all-ttl.sh: build-ttl.sh
source .image.env && IMAGE=ttl.sh/${CURRENT_USER}/kotsadm-migrations:24h make -C migrations build_schema
source .image.env && \
IMAGE=ttl.sh/${CURRENT_USER}/kotsadm-migrations:24h \
DOCKER_BUILD_ARGS="--platform $(GOOS)/$(GOARCH)" \
make -C migrations build_schema

docker pull kotsadm/minio:${MINIO_TAG}
docker pull --platform $(GOOS)/$(GOARCH)" kotsadm/minio:${MINIO_TAG}
docker tag kotsadm/minio:${MINIO_TAG} ttl.sh/${CURRENT_USER}/minio:${MINIO_TAG}
docker push ttl.sh/${CURRENT_USER}/minio:${MINIO_TAG}

docker pull kotsadm/rqlite:${RQLITE_TAG}
docker pull --platform $(GOOS)/$(GOARCH)" kotsadm/rqlite:${RQLITE_TAG}
docker tag kotsadm/rqlite:${RQLITE_TAG} ttl.sh/${CURRENT_USER}/rqlite:${RQLITE_TAG}
docker push ttl.sh/${CURRENT_USER}/rqlite:${RQLITE_TAG}

Expand Down
3 changes: 2 additions & 1 deletion migrations/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SHELL:=/bin/bash
SCHEMAHERO_TAG ?= 0.17.9
DOCKER_BUILD_ARGS ?=

build_schema:
docker build --pull --build-arg SCHEMAHERO_TAG=${SCHEMAHERO_TAG} -f deploy/Dockerfile -t ${IMAGE} .
docker build --pull --build-arg SCHEMAHERO_TAG=${SCHEMAHERO_TAG} ${DOCKER_BUILD_ARGS} -f deploy/Dockerfile -t ${IMAGE} .
docker push ${IMAGE}
2 changes: 1 addition & 1 deletion pkg/embeddedcluster/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func MaybeStartClusterUpgrade(ctx context.Context, store store.Store, kotsKinds

artifacts := getArtifactsFromInstallation(kotsKinds.Installation, kotsKinds.License.Spec.AppSlug)

if err := startClusterUpgrade(ctx, spec, artifacts, *kotsKinds.License); err != nil {
if err := startClusterUpgrade(ctx, spec, artifacts, *kotsKinds.License, kotsKinds.Installation.Spec.VersionLabel); err != nil {

Check failure on line 78 in pkg/embeddedcluster/monitor.go

View workflow job for this annotation

GitHub Actions / ci-test-kots

not enough arguments in call to startClusterUpgrade

Check failure on line 78 in pkg/embeddedcluster/monitor.go

View workflow job for this annotation

GitHub Actions / vet-kots

not enough arguments in call to startClusterUpgrade

Check failure on line 78 in pkg/embeddedcluster/monitor.go

View workflow job for this annotation

GitHub Actions / build-kots

not enough arguments in call to startClusterUpgrade
return fmt.Errorf("failed to start cluster upgrade: %w", err)
}
logger.Info("started cluster upgrade")
Expand Down
57 changes: 57 additions & 0 deletions pkg/embeddedcluster/oras.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package embeddedcluster

import (
"context"
"fmt"

"go.uber.org/multierr"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content/file"
"oras.land/oras-go/v2/registry"
"oras.land/oras-go/v2/registry/remote"
)

type pullArtifactOptions struct {
client remote.Client
}

// pullArtifact fetches an artifact from the registry pointed by 'from'. The artifact
// is stored in a temporary directory and the path to this directory is returned.
// Callers are responsible for removing the temporary directory when it is no longer
// needed. In case of error, the temporary directory is removed here.
func pullArtifact(ctx context.Context, srcRepo, dstDir string, opts pullArtifactOptions) error {
imgref, err := registry.ParseReference(srcRepo)
if err != nil {
return fmt.Errorf("parse image reference: %w", err)
}

repo, err := remote.NewRepository(srcRepo)
if err != nil {
return fmt.Errorf("create repository: %w", err)
}

fs, err := file.New(dstDir)
if err != nil {
return fmt.Errorf("create file store: %w", err)
}
defer fs.Close()

if opts.client != nil {
repo.Client = opts.client
}

tag := imgref.Reference
_, tlserr := oras.Copy(ctx, repo, tag, fs, tag, oras.DefaultCopyOptions)
if tlserr == nil {
return nil
}

// if we fail to fetch the artifact using https we gonna try once more using plain
// http as some versions of the registry were deployed without tls.
repo.PlainHTTP = true
if _, err := oras.Copy(ctx, repo, tag, fs, tag, oras.DefaultCopyOptions); err != nil {
err = multierr.Combine(tlserr, err)
return fmt.Errorf("fetch artifacts with or without tls: %w", err)
}
return nil
}
38 changes: 38 additions & 0 deletions pkg/embeddedcluster/oras_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package embeddedcluster

import (
"context"
"testing"
)

func x_Test_pullArtifact(t *testing.T) {
type args struct {
ctx context.Context
srcRepo string
opts pullArtifactOptions
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "test1",
args: args{
ctx: context.Background(),
srcRepo: "ttl.sh/ethan/embedded-cluster-operator-bin:24h",
opts: pullArtifactOptions{},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpdir := t.TempDir()
t.Log(tmpdir)
if err := pullArtifact(tt.args.ctx, tt.args.srcRepo, tmpdir, tt.args.opts); (err != nil) != tt.wantErr {
t.Errorf("pullArtifact() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
Loading

0 comments on commit 5aef836

Please sign in to comment.