Skip to content

Commit 855f35e

Browse files
moved add-cluster manifests to csdp-official repo (#470)
* moved add-cluster manifests to csdp-official repo * updated version to 0.0.419 Co-authored-by: Noam Gal <noam.gal@codefresh.io>
1 parent cd76ad2 commit 855f35e

24 files changed

+51
-433
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ IMAGE_REPOSITORY?=quay.io
88
IMAGE_NAMESPACE?=codefresh
99

1010
RUNTIME_DEF_URL="https://github.com/codefresh-io/cli-v2/releases/latest/download/runtime.yaml"
11-
ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/cli-v2/manifests/add-cluster/kustomize"
11+
ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/csdp-official/add-cluster/kustomize"
12+
FALLBACK_ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/cli-v2/manifests/add-cluster/kustomize"
1213

1314
DEV_RUNTIME_DEF_URL="manifests/runtime.yaml"
14-
DEV_ADD_CLUSTER_DEF_URL="../manifests/add-cluster/kustomize"
15+
DEV_ADD_CLUSTER_DEF_URL="https://github.com/codefresh-io/csdp-official/add-cluster/kustomize" # specify dev branch using ?ref=<branch> here if you want to test a change
1516

1617
CLI_SRCS := $(shell find . -name '*.go')
1718

@@ -105,6 +106,7 @@ $(OUT_DIR)/$(CLI_NAME)-%: $(CLI_SRCS)
105106
OUT_FILE=$(OUT_DIR)/$(CLI_NAME)-$* \
106107
RUNTIME_DEF_URL=$(RUNTIME_DEF_URL) \
107108
ADD_CLUSTER_DEF_URL=$(ADD_CLUSTER_DEF_URL) \
109+
FALLBACK_ADD_CLUSTER_DEF_URL=$(FALLBACK_ADD_CLUSTER_DEF_URL) \
108110
SEGMENT_WRITE_KEY=$(SEGMENT_WRITE_KEY) \
109111
MAIN=./cmd \
110112
./hack/build.sh

cmd/commands/cluster.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ func runClusterAdd(ctx context.Context, opts *ClusterAddOptions) error {
146146
return fmt.Errorf("failed getting server for context \"%s\": %w", opts.kubeContext, err)
147147
}
148148

149-
csdpToken := cfConfig.GetCurrentContext().Token
150-
k, nameSuffix := createAddClusterKustomization(ingressUrl, opts.clusterName, server, csdpToken, *runtime.RuntimeVersion)
149+
log.G(ctx).Info("Building \"add-cluster\" manifests")
151150

152-
manifests, err := kustutil.BuildKustomization(k)
151+
csdpToken := cfConfig.GetCurrentContext().Token
152+
manifests, nameSuffix, err := createAddClusterManifests(ingressUrl, opts.clusterName, server, csdpToken, *runtime.RuntimeVersion)
153153
if err != nil {
154-
return fmt.Errorf("failed building kustomization: %w", err)
154+
return fmt.Errorf("failed getting add-cluster resources: %w", err)
155155
}
156156

157157
if opts.dryRun {
@@ -164,7 +164,9 @@ func runClusterAdd(ctx context.Context, opts *ClusterAddOptions) error {
164164
return fmt.Errorf("failed applying manifests to cluster: %w", err)
165165
}
166166

167-
return kubeutil.WaitForJob(ctx, opts.kubeFactory, "kube-system", fmt.Sprintf("%s%s", store.Get().AddClusterJobName, nameSuffix))
167+
jobName := strings.TrimSuffix(store.Get().AddClusterJobName, "-") + nameSuffix
168+
169+
return kubeutil.WaitForJob(ctx, opts.kubeFactory, "kube-system", jobName)
168170
}
169171

170172
func setClusterName(ctx context.Context, opts *ClusterAddOptions) error {
@@ -204,7 +206,7 @@ func sanitizeClusterName(name string) string {
204206

205207
name = strings.ToLower(name)
206208
name = invalidDNSNameChars.ReplaceAllString(name, "-")
207-
// saving space for 2 chars in case a cluster with the sanitized name already exists
209+
// saving space for 2 chars in case a cluster with the sanitized name already exists
208210
if len(name) > (maxDNSNameLength - 2) {
209211
name = name[:(maxDNSNameLength - 2)]
210212
}
@@ -217,7 +219,7 @@ func ensureNoClusterNameDuplicates(ctx context.Context, name string, runtimeName
217219
if err != nil {
218220
return "", fmt.Errorf("failed to get clusters list: %w", err)
219221
}
220-
222+
221223
suffix := getSuffixToClusterName(clusters, name, name, 0)
222224
if suffix != 0 {
223225
return fmt.Sprintf("%s-%d", name, suffix), nil
@@ -239,11 +241,11 @@ func getSuffixToClusterName(clusters []model.Cluster, name string, tempName stri
239241
return counter
240242
}
241243

242-
func createAddClusterKustomization(ingressUrl, contextName, server, csdpToken, version string) (*kusttypes.Kustomization, string) {
244+
func createAddClusterManifests(ingressUrl, contextName, server, csdpToken, version string) ([]byte, string, error) {
243245
nameSuffix := getClusterResourcesNameSuffix()
244246
resourceUrl := store.AddClusterDefURL
245-
if strings.HasPrefix(resourceUrl, "http") {
246-
resourceUrl = fmt.Sprintf("%s?ref=v%s", resourceUrl, version)
247+
if strings.HasPrefix(resourceUrl, "http") && !strings.Contains(resourceUrl, "?ref=") {
248+
resourceUrl = fmt.Sprintf("%s?ref=%s", resourceUrl, version)
247249
}
248250

249251
k := &kusttypes.Kustomization{
@@ -284,7 +286,23 @@ func createAddClusterKustomization(ingressUrl, contextName, server, csdpToken, v
284286
}
285287
k.FixKustomizationPostUnmarshalling()
286288
util.Die(k.FixKustomizationPreMarshalling())
287-
return k, nameSuffix
289+
290+
manifests, err := kustutil.BuildKustomization(k)
291+
if err != nil {
292+
// go to fallback add-cluster manifests
293+
// remove this once all manifests has been moved official-csdp repo.
294+
// once we are sure no one will be looking for those manifests in cli-v2 we can remove this.
295+
fallbackResourceUrl := fmt.Sprintf("%s?ref=v%s", store.FallbackAddClusterDefURL, version)
296+
k.Resources[0] = fallbackResourceUrl
297+
log.G().Warnf("Failed to get \"add-cluster\" manifests from %s, using fallback of %s", resourceUrl, fallbackResourceUrl)
298+
299+
manifests, err = kustutil.BuildKustomization(k)
300+
if err != nil {
301+
return nil, "", fmt.Errorf("failed to build kustomization: %w", err)
302+
}
303+
}
304+
305+
return manifests, nameSuffix, nil
288306
}
289307

290308
func getClusterResourcesNameSuffix() string {

hack/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ go build -ldflags=" \
1515
-X 'github.com/codefresh-io/cli-v2/pkg/store.gitCommit=${GIT_COMMIT}' \
1616
-X 'github.com/codefresh-io/cli-v2/pkg/store.RuntimeDefURL=${RUNTIME_DEF_URL}' \
1717
-X 'github.com/codefresh-io/cli-v2/pkg/store.AddClusterDefURL=${ADD_CLUSTER_DEF_URL}' \
18+
-X 'github.com/codefresh-io/cli-v2/pkg/store.FallbackAddClusterDefURL=${FALLBACK_ADD_CLUSTER_DEF_URL}' \
1819
-X 'github.com/codefresh-io/cli-v2/pkg/store.segmentWriteKey=${SEGMENT_WRITE_KEY}'" \
1920
-v -o ${OUT_FILE} ${MAIN}

manifests/add-cluster/Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/add-cluster/add-cluster.sh

Lines changed: 0 additions & 55 deletions
This file was deleted.

manifests/add-cluster/helm/.helmignore

Lines changed: 0 additions & 23 deletions
This file was deleted.

manifests/add-cluster/helm/Chart.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

manifests/add-cluster/helm/templates/_helpers.tpl

Lines changed: 0 additions & 58 deletions
This file was deleted.

manifests/add-cluster/helm/templates/clusterrole.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.

manifests/add-cluster/helm/templates/clusterrolebinding.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)