Skip to content

Commit c4efeb3

Browse files
author
Craig O'Donnell
committed
pass embedded cluster artifacts in upstream upgrade
1 parent 1013d8e commit c4efeb3

File tree

9 files changed

+55
-3
lines changed

9 files changed

+55
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ require (
4949
github.com/pkg/errors v0.9.1
5050
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
5151
github.com/replicatedhq/embedded-cluster-kinds v1.1.2
52-
github.com/replicatedhq/kotskinds v0.0.0-20240326213823-6a0ed11e7397
52+
github.com/replicatedhq/kotskinds v0.0.0-20240402213802-a6d75e97be70
5353
github.com/replicatedhq/kurlkinds v1.5.0
5454
github.com/replicatedhq/troubleshoot v0.87.0
5555
github.com/replicatedhq/yaml/v3 v3.0.0-beta5-replicatedhq

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,8 @@ github.com/replicatedhq/embedded-cluster-kinds v1.1.2 h1:2ITzcUzh5uh0fsnfZsVHvkw
13101310
github.com/replicatedhq/embedded-cluster-kinds v1.1.2/go.mod h1:LheSDOgMngMRAbwAj0sVZUVv2ciKIVR2bYTMeOBGwlg=
13111311
github.com/replicatedhq/kotskinds v0.0.0-20240326213823-6a0ed11e7397 h1:JNuBcFH9D3Osyi+1QUwdvaAklEd6HXznqZDfpWlr73M=
13121312
github.com/replicatedhq/kotskinds v0.0.0-20240326213823-6a0ed11e7397/go.mod h1:QjhIUu3+OmHZ09u09j3FCoTt8F3BYtQglS+OLmftu9I=
1313+
github.com/replicatedhq/kotskinds v0.0.0-20240402213802-a6d75e97be70 h1:55fMr60YysSf+ac5zeW+xTIIJ8edUpAjorQyFn0iP2c=
1314+
github.com/replicatedhq/kotskinds v0.0.0-20240402213802-a6d75e97be70/go.mod h1:QjhIUu3+OmHZ09u09j3FCoTt8F3BYtQglS+OLmftu9I=
13131315
github.com/replicatedhq/kurlkinds v1.5.0 h1:zZ0PKNeh4kXvSzVGkn62DKTo314GxhXg1TSB3azURMc=
13141316
github.com/replicatedhq/kurlkinds v1.5.0/go.mod h1:rUpBMdC81IhmJNCWMU/uRsMETv9P0xFoMvdSP/TAr5A=
13151317
github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851 h1:eRlNDHxGfVkPCRXbA4BfQJvt5DHjFiTtWy3R/t4djyY=

pkg/embeddedcluster/util.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8+
"path/filepath"
89
"regexp"
910
"sort"
1011
"time"
1112

1213
embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-kinds/apis/v1beta1"
14+
"github.com/replicatedhq/kots/pkg/imageutil"
1315
"github.com/replicatedhq/kots/pkg/k8sutil"
1416
"github.com/replicatedhq/kots/pkg/logger"
1517
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
@@ -171,3 +173,21 @@ func startClusterUpgrade(ctx context.Context, newcfg embeddedclusterv1beta1.Conf
171173
}
172174
return nil
173175
}
176+
177+
type EmbeddedClusterArtifactOCIPathOptions struct {
178+
RegistryHost string
179+
RegistryNamespace string
180+
ChannelID string
181+
UpdateCursor string
182+
VersionLabel string
183+
}
184+
185+
// EmbeddedClusterArtifactOCIPath returns the OCI path for an embedded cluster artifact given
186+
// the artifact filename and details about the configured registry and channel release.
187+
func EmbeddedClusterArtifactOCIPath(filename string, opts EmbeddedClusterArtifactOCIPathOptions) string {
188+
name := filepath.Base(filename)
189+
repository := filepath.Join("embedded-cluster", imageutil.SanitizeRepo(name))
190+
tag := imageutil.SanitizeTag(fmt.Sprintf("%s-%s-%s", opts.ChannelID, opts.UpdateCursor, opts.VersionLabel))
191+
artifact := fmt.Sprintf("%s:%s", filepath.Join(opts.RegistryHost, opts.RegistryNamespace, repository), tag)
192+
return artifact
193+
}

pkg/pull/pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) {
216216
fetchOptions.CurrentVersionIsRequired = installation.Spec.IsRequired
217217
fetchOptions.CurrentReplicatedRegistryDomain = installation.Spec.ReplicatedRegistryDomain
218218
fetchOptions.CurrentReplicatedProxyDomain = installation.Spec.ReplicatedProxyDomain
219+
fetchOptions.CurrentEmbeddedClusterArtifacts = installation.Spec.EmbeddedClusterArtifacts
219220
}
220221

221222
if pullOptions.AirgapRoot != "" {

pkg/rewrite/rewrite.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func Rewrite(rewriteOptions RewriteOptions) error {
7777
CurrentReplicatedRegistryDomain: rewriteOptions.Installation.Spec.ReplicatedRegistryDomain,
7878
CurrentReplicatedProxyDomain: rewriteOptions.Installation.Spec.ReplicatedProxyDomain,
7979
CurrentReplicatedChartNames: rewriteOptions.Installation.Spec.ReplicatedChartNames,
80+
CurrentEmbeddedClusterArtifacts: rewriteOptions.Installation.Spec.EmbeddedClusterArtifacts,
8081
EncryptionKey: rewriteOptions.Installation.Spec.EncryptionKey,
8182
License: rewriteOptions.License,
8283
AppSequence: rewriteOptions.AppSequence,

pkg/upstream/fetch.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/pkg/errors"
77
"github.com/replicatedhq/kots/pkg/crypto"
8+
"github.com/replicatedhq/kots/pkg/embeddedcluster"
89
"github.com/replicatedhq/kots/pkg/replicatedapp"
910
"github.com/replicatedhq/kots/pkg/upstream/types"
1011
"github.com/replicatedhq/kots/pkg/util"
@@ -50,6 +51,7 @@ func downloadUpstream(upstreamURI string, fetchOptions *types.FetchOptions) (*ty
5051
pickReplicatedRegistryDomain(fetchOptions),
5152
pickReplicatedProxyDomain(fetchOptions),
5253
pickReplicatedChartNames(fetchOptions),
54+
pickEmbeddedClusterArtifacts(fetchOptions),
5355
fetchOptions.AppSlug,
5456
fetchOptions.AppSequence,
5557
fetchOptions.Airgap != nil,
@@ -118,3 +120,22 @@ func pickReplicatedChartNames(fetchOptions *types.FetchOptions) []string {
118120
}
119121
return fetchOptions.CurrentReplicatedChartNames
120122
}
123+
124+
func pickEmbeddedClusterArtifacts(fetchOptions *types.FetchOptions) []string {
125+
if fetchOptions.Airgap != nil {
126+
opts := embeddedcluster.EmbeddedClusterArtifactOCIPathOptions{
127+
RegistryHost: fetchOptions.LocalRegistry.Hostname,
128+
RegistryNamespace: fetchOptions.LocalRegistry.Namespace,
129+
ChannelID: fetchOptions.Airgap.Spec.ChannelID,
130+
UpdateCursor: fetchOptions.Airgap.Spec.UpdateCursor,
131+
VersionLabel: fetchOptions.Airgap.Spec.VersionLabel,
132+
}
133+
return []string{
134+
embeddedcluster.EmbeddedClusterArtifactOCIPath(fetchOptions.Airgap.Spec.EmbeddedClusterArtifacts.Binary, opts),
135+
embeddedcluster.EmbeddedClusterArtifactOCIPath(fetchOptions.Airgap.Spec.EmbeddedClusterArtifacts.Charts, opts),
136+
embeddedcluster.EmbeddedClusterArtifactOCIPath(fetchOptions.Airgap.Spec.EmbeddedClusterArtifacts.Images, opts),
137+
embeddedcluster.EmbeddedClusterArtifactOCIPath(fetchOptions.Airgap.Spec.EmbeddedClusterArtifacts.Metadata, opts),
138+
}
139+
}
140+
return fetchOptions.CurrentEmbeddedClusterArtifacts
141+
}

pkg/upstream/replicated.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Release struct {
5656
ReplicatedRegistryDomain string
5757
ReplicatedProxyDomain string
5858
ReplicatedChartNames []string
59+
EmbeddedClusterArtifacts []string
5960
Manifests map[string][]byte
6061
}
6162

@@ -127,6 +128,7 @@ func downloadReplicated(
127128
replicatedRegistryDomain string,
128129
replicatedProxyDomain string,
129130
replicatedChartNames []string,
131+
embeddedClusterArtifacts []string,
130132
appSlug string,
131133
appSequence int64,
132134
isAirgap bool,
@@ -138,7 +140,7 @@ func downloadReplicated(
138140
var release *Release
139141

140142
if localPath != "" {
141-
parsedLocalRelease, err := readReplicatedAppFromLocalPath(localPath, updateCursor, versionLabel, isRequired, replicatedRegistryDomain, replicatedProxyDomain, replicatedChartNames)
143+
parsedLocalRelease, err := readReplicatedAppFromLocalPath(localPath, updateCursor, versionLabel, isRequired, replicatedRegistryDomain, replicatedProxyDomain, replicatedChartNames, embeddedClusterArtifacts)
142144
if err != nil {
143145
return nil, errors.Wrap(err, "failed to read replicated app from local path")
144146
}
@@ -299,12 +301,13 @@ func downloadReplicated(
299301
ReplicatedRegistryDomain: release.ReplicatedRegistryDomain,
300302
ReplicatedProxyDomain: release.ReplicatedProxyDomain,
301303
ReplicatedChartNames: release.ReplicatedChartNames,
304+
EmbeddedClusterArtifacts: embeddedClusterArtifacts,
302305
}
303306

304307
return upstream, nil
305308
}
306309

307-
func readReplicatedAppFromLocalPath(localPath string, localCursor replicatedapp.ReplicatedCursor, versionLabel string, isRequired bool, replicatedRegistryDomain string, replicatedProxyDomain string, replicatedChartNames []string) (*Release, error) {
310+
func readReplicatedAppFromLocalPath(localPath string, localCursor replicatedapp.ReplicatedCursor, versionLabel string, isRequired bool, replicatedRegistryDomain string, replicatedProxyDomain string, replicatedChartNames []string, embeddedClusterArtifacts []string) (*Release, error) {
308311
release := Release{
309312
Manifests: make(map[string][]byte),
310313
UpdateCursor: localCursor,
@@ -313,6 +316,7 @@ func readReplicatedAppFromLocalPath(localPath string, localCursor replicatedapp.
313316
ReplicatedRegistryDomain: replicatedRegistryDomain,
314317
ReplicatedProxyDomain: replicatedProxyDomain,
315318
ReplicatedChartNames: replicatedChartNames,
319+
EmbeddedClusterArtifacts: embeddedClusterArtifacts,
316320
}
317321

318322
err := filepath.Walk(localPath,

pkg/upstream/types/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Upstream struct {
3737
ReplicatedRegistryDomain string
3838
ReplicatedProxyDomain string
3939
ReplicatedChartNames []string
40+
EmbeddedClusterArtifacts []string
4041
EncryptionKey string
4142
}
4243

@@ -104,6 +105,7 @@ type FetchOptions struct {
104105
CurrentReplicatedRegistryDomain string
105106
CurrentReplicatedProxyDomain string
106107
CurrentReplicatedChartNames []string
108+
CurrentEmbeddedClusterArtifacts []string
107109
ChannelChanged bool
108110
AppSlug string
109111
AppSequence int64

pkg/upstream/write.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func WriteUpstream(u *types.Upstream, options types.WriteOptions) error {
141141
ReplicatedRegistryDomain: u.ReplicatedRegistryDomain,
142142
ReplicatedProxyDomain: u.ReplicatedProxyDomain,
143143
ReplicatedChartNames: u.ReplicatedChartNames,
144+
EmbeddedClusterArtifacts: u.EmbeddedClusterArtifacts,
144145
EncryptionKey: encryptionKey,
145146
},
146147
}

0 commit comments

Comments
 (0)