Skip to content

Commit fd117cc

Browse files
authored
include k0s images within metadata output (#439)
* include k0s images within metadata output * what happens if we use the cluster config from the compiled library * break up 'build' and 'export metadata' github steps * f * 'go get' k0s when updating binary import * do not zero out images * validate test * the test worked * ensure k0s go mod version matches at build time
1 parent 85266d9 commit fd117cc

File tree

12 files changed

+99
-72
lines changed

12 files changed

+99
-72
lines changed

.github/workflows/dependencies.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ jobs:
1111
steps:
1212
- name: Check out repo
1313
uses: actions/checkout@v4
14+
- name: Set up Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: "1.21"
1418
- name: AdminConsole
1519
run: |
1620
export VERSION=`curl https://api.github.com/repos/replicatedhq/kots-helm/tags | jq -r .[].name | grep -v alpha | head -1 | tr -d v`
@@ -35,6 +39,7 @@ jobs:
3539
if [ "$CURVERSION" != "$VERSION" ]; then
3640
sed -i "/^K0S_VERSION/c\K0S_VERSION = $VERSION" Makefile
3741
sed -i "/^K0S_BINARY_SOURCE_OVERRIDE/c\K0S_BINARY_SOURCE_OVERRIDE =" Makefile
42+
go get github.com/k0sproject/k0s@${VERSION}
3843
fi
3944
- name: Troubleshoot
4045
run: |

.github/workflows/pull-request.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ jobs:
5353
- name: Build Linux AMD64
5454
run: |
5555
make embedded-cluster-linux-amd64 VERSION=dev-$SHORT_SHA
56+
- name: Output Metadata
57+
run: |
5658
./output/bin/embedded-cluster version metadata > metadata.json
5759
- name: Install Replicated CLI
5860
run: |

.github/workflows/release-dev.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
run: |
2222
make embedded-cluster-linux-amd64
2323
tar -C output/bin -czvf embedded-cluster-linux-amd64.tgz embedded-cluster
24+
- name: Output Metadata
25+
run: |
2426
./output/bin/embedded-cluster version metadata > metadata.json
2527
- name: Publish development release
2628
uses: marvinpinto/action-automatic-releases@latest

.github/workflows/release-prod.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
run: |
2424
make embedded-cluster-linux-amd64 VERSION=$TAG_NAME
2525
tar -C output/bin -czvf embedded-cluster-linux-amd64.tgz embedded-cluster
26+
- name: Output Metadata
27+
run: |
2628
./output/bin/embedded-cluster version metadata > metadata.json
2729
- name: Cache Staging Files
2830
env:

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,24 @@ output/bin/embedded-cluster-release-builder:
8181
embedded-release: embedded-cluster-linux-amd64 output/tmp/release.tar.gz output/bin/embedded-cluster-release-builder
8282
./output/bin/embedded-cluster-release-builder output/bin/embedded-cluster output/tmp/release.tar.gz output/bin/embedded-cluster
8383

84+
go.mod: Makefile
85+
go get github.com/k0sproject/k0s@$(K0S_VERSION)
86+
go mod tidy
87+
8488
.PHONY: static
8589
static: pkg/goods/bins/k0s \
8690
pkg/goods/bins/kubectl-preflight \
8791
pkg/goods/bins/kubectl \
8892
pkg/goods/bins/kubectl-support_bundle
8993

9094
.PHONY: embedded-cluster-linux-amd64
91-
embedded-cluster-linux-amd64: static
95+
embedded-cluster-linux-amd64: static go.mod
9296
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LD_FLAGS)" -o ./output/bin/$(APP_NAME) ./cmd/embedded-cluster
9397

9498
# for testing
95-
.PHONY: embedded-cluster-darwin-amd64
96-
embedded-cluster-darwin-amd64:
97-
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LD_FLAGS)" -o ./output/bin/$(APP_NAME) ./cmd/embedded-cluster
99+
.PHONY: embedded-cluster-darwin-arm64
100+
embedded-cluster-darwin-arm64: go.mod
101+
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "$(LD_FLAGS)" -o ./output/bin/$(APP_NAME) ./cmd/embedded-cluster
98102

99103
.PHONY: unit-tests
100104
unit-tests:

cmd/embedded-cluster/install.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,15 @@ func checkLicenseMatches(c *cli.Context) error {
162162
// createK0sConfig creates a new k0s.yaml configuration file. The file is saved in the
163163
// global location (as returned by defaults.PathToK0sConfig()). If a file already sits
164164
// there, this function returns an error.
165-
func ensureK0sConfig(c *cli.Context, useprompt bool) error {
165+
func ensureK0sConfig(c *cli.Context) error {
166166
cfgpath := defaults.PathToK0sConfig()
167167
if _, err := os.Stat(cfgpath); err == nil {
168168
return fmt.Errorf("configuration file already exists")
169169
}
170170
if err := os.MkdirAll(filepath.Dir(cfgpath), 0755); err != nil {
171171
return fmt.Errorf("unable to create directory: %w", err)
172172
}
173-
cfg, err := config.RenderK0sConfig(c.Context)
174-
if err != nil {
175-
return fmt.Errorf("unable to render config: %w", err)
176-
}
173+
cfg := config.RenderK0sConfig()
177174
opts := []addons.Option{}
178175
if c.Bool("no-prompt") {
179176
opts = append(opts, addons.WithoutPrompt())
@@ -188,6 +185,7 @@ func ensureK0sConfig(c *cli.Context, useprompt bool) error {
188185
if err := config.UpdateHelmConfigs(cfg, opts...); err != nil {
189186
return fmt.Errorf("unable to update helm configs: %w", err)
190187
}
188+
var err error
191189
if cfg, err = applyUnsupportedOverrides(c, cfg); err != nil {
192190
return fmt.Errorf("unable to apply unsupported overrides: %w", err)
193191
}
@@ -357,7 +355,7 @@ var installCommand = &cli.Command{
357355
return err
358356
}
359357
logrus.Debugf("creating k0s configuration file")
360-
if err := ensureK0sConfig(c, !c.Bool("no-prompt")); err != nil {
358+
if err := ensureK0sConfig(c); err != nil {
361359
err := fmt.Errorf("unable to create config file: %w", err)
362360
metrics.ReportApplyFinished(c, err)
363361
return err

cmd/embedded-cluster/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type ReleaseMetadata struct {
88
Versions map[string]string
99
K0sSHA string
1010
K0sBinaryURL string
11+
K0sImages []string
1112
Configs v1beta1.HelmExtensions
1213
Protected map[string][]string
1314
}

cmd/embedded-cluster/version.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/replicatedhq/embedded-cluster/cmd/embedded-cluster/types"
76
"sort"
87
"strings"
98

109
"github.com/jedib0t/go-pretty/table"
10+
"github.com/k0sproject/k0s/pkg/airgap"
11+
k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
1112
"github.com/urfave/cli/v2"
1213

13-
k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
14+
"github.com/replicatedhq/embedded-cluster/cmd/embedded-cluster/types"
1415
"github.com/replicatedhq/embedded-cluster/pkg/addons"
1516
"github.com/replicatedhq/embedded-cluster/pkg/config"
1617
"github.com/replicatedhq/embedded-cluster/pkg/defaults"
@@ -96,6 +97,14 @@ var metadataCommand = &cli.Command{
9697
return fmt.Errorf("unable to get protected fields: %w", err)
9798
}
9899
meta.Protected = protectedFields
100+
101+
// Render k0s config to get the images contained within
102+
k0sConfig := config.RenderK0sConfig()
103+
if err != nil {
104+
return fmt.Errorf("unable to render k0s config: %w", err)
105+
}
106+
meta.K0sImages = airgap.GetImageURIs(k0sConfig.Spec, true)
107+
99108
data, err := json.MarshalIndent(meta, "", "\t")
100109
if err != nil {
101110
return fmt.Errorf("unable to marshal versions: %w", err)

e2e/version_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ func TestVersion(t *testing.T) {
6464
}
6565
}
6666

67+
expectedImageSubstrings := []string{"coredns", "calico-cni", "metrics-server", "pause", "envoy"}
68+
for _, v := range expectedImageSubstrings {
69+
found := false
70+
71+
for _, image := range parsed.K0sImages {
72+
if strings.Contains(image, v) {
73+
found = true
74+
break
75+
}
76+
}
77+
if !found {
78+
t.Errorf("missing image substring %q in image metadata output", v)
79+
failed = true
80+
}
81+
}
82+
6783
for _, foundChart := range parsed.Configs.Charts {
6884
if strings.Contains(foundChart.Values, "embeddedClusterID") {
6985
t.Errorf("metadata output for chart %s contains embeddedClusterID", foundChart.Name)

go.mod

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ require (
1111
github.com/gosimple/slug v1.14.0
1212
github.com/jedib0t/go-pretty v4.3.0+incompatible
1313
github.com/k0sproject/dig v0.2.0
14+
github.com/k0sproject/k0s v1.29.3-0.20240220215935-6a63dc9024ce
1415
github.com/replicatedhq/embedded-cluster-operator v0.24.1
15-
github.com/replicatedhq/embedded-cluster-utils v0.0.0-20240214185439-68a1dfae58be
16+
github.com/replicatedhq/embedded-cluster-utils v0.0.0-20240308200300-87d150770db8
1617
github.com/replicatedhq/kotskinds v0.0.0-20230724164735-f83482cc9cfe
1718
github.com/replicatedhq/troubleshoot v0.83.0
1819
github.com/sirupsen/logrus v1.9.3
1920
github.com/stretchr/testify v1.9.0
2021
github.com/urfave/cli/v2 v2.27.1
2122
golang.org/x/term v0.18.0
2223
gopkg.in/yaml.v2 v2.4.0
24+
gopkg.in/yaml.v3 v3.0.1
2325
k8s.io/api v0.29.2
2426
k8s.io/apimachinery v0.29.2
2527
sigs.k8s.io/controller-runtime v0.17.2
@@ -33,7 +35,7 @@ require (
3335
github.com/coreos/go-semver v0.3.1 // indirect
3436
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
3537
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
36-
github.com/frankban/quicktest v1.14.5 // indirect
38+
github.com/frankban/quicktest v1.14.6 // indirect
3739
github.com/fsnotify/fsnotify v1.7.0 // indirect
3840
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3941
github.com/google/go-cmp v0.6.0 // indirect
@@ -50,18 +52,18 @@ require (
5052
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
5153
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
5254
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
53-
go.etcd.io/etcd/api/v3 v3.5.10 // indirect
54-
go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect
55-
go.etcd.io/etcd/client/v3 v3.5.10 // indirect
56-
golang.org/x/crypto v0.19.0 // indirect
55+
go.etcd.io/etcd/api/v3 v3.5.12 // indirect
56+
go.etcd.io/etcd/client/pkg/v3 v3.5.12 // indirect
57+
go.etcd.io/etcd/client/v3 v3.5.12 // indirect
58+
golang.org/x/crypto v0.21.0 // indirect
5759
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
5860
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
5961
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
6062
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
6163
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
62-
google.golang.org/grpc v1.59.0 // indirect
63-
helm.sh/helm/v3 v3.14.0 // indirect
64-
k8s.io/component-base v0.29.0 // indirect
64+
google.golang.org/grpc v1.60.1 // indirect
65+
helm.sh/helm/v3 v3.14.1 // indirect
66+
k8s.io/component-base v0.29.2 // indirect
6567
)
6668

6769
require (
@@ -78,10 +80,10 @@ require (
7880
github.com/go-macaroon-bakery/macaroon-bakery/v3 v3.0.1 // indirect
7981
github.com/go-macaroon-bakery/macaroonpb v1.0.0 // indirect
8082
github.com/go-openapi/errors v0.20.3 // indirect
81-
github.com/go-openapi/jsonpointer v0.20.0 // indirect
83+
github.com/go-openapi/jsonpointer v0.20.2 // indirect
8284
github.com/go-openapi/jsonreference v0.20.2 // indirect
8385
github.com/go-openapi/strfmt v0.21.7 // indirect
84-
github.com/go-openapi/swag v0.22.4 // indirect
86+
github.com/go-openapi/swag v0.22.5 // indirect
8587
github.com/gogo/protobuf v1.3.2 // indirect
8688
github.com/golang/protobuf v1.5.3 // indirect
8789
github.com/google/gnostic-models v0.6.8 // indirect
@@ -96,7 +98,6 @@ require (
9698
github.com/json-iterator/go v1.1.12 // indirect
9799
github.com/juju/webbrowser v1.0.0 // indirect
98100
github.com/julienschmidt/httprouter v1.3.0 // indirect
99-
github.com/k0sproject/k0s v1.28.5-0.20231116142149-82f76181191c
100101
github.com/k0sproject/version v0.6.0 // indirect
101102
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
102103
github.com/kr/fs v0.1.0 // indirect
@@ -128,7 +129,7 @@ require (
128129
go.mongodb.org/mongo-driver v1.11.3 // indirect
129130
go.uber.org/multierr v1.11.0 // indirect
130131
go.uber.org/zap v1.26.0 // indirect
131-
golang.org/x/net v0.20.0 // indirect
132+
golang.org/x/net v0.21.0 // indirect
132133
golang.org/x/oauth2 v0.15.0 // indirect
133134
golang.org/x/sys v0.18.0 // indirect
134135
golang.org/x/text v0.14.0 // indirect
@@ -140,8 +141,7 @@ require (
140141
gopkg.in/inf.v0 v0.9.1 // indirect
141142
gopkg.in/macaroon.v2 v2.1.0 // indirect
142143
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
143-
gopkg.in/yaml.v3 v3.0.1
144-
k8s.io/apiextensions-apiserver v0.29.0 // indirect
144+
k8s.io/apiextensions-apiserver v0.29.2 // indirect
145145
k8s.io/client-go v0.29.2 // indirect
146146
k8s.io/klog/v2 v2.120.1 // indirect
147147
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect

0 commit comments

Comments
 (0)