Repository: argoproj-labs/applicationset (go)

Issue:
Update build scripts to target  'argoproj/applicationset' on quay.io 
The default build/install artifacts currently point to an old org/repo, and since we are already hosting the `0.1.0` image under the `argoproj/argocd-applicationset` on quay.io, we should update the build scripts to point to this location as well.

Pull request description:
Update build scripts to target 'argoproj/applicationset' on quay.io
This PR switches from Docker Hub to quay.io for official image location, and argoproj as the organization: https://quay.io/repository/argoproj/argocd-applicationset

Fixes #234 

Patch:
diff --git a/Makefile b/Makefile
index e12a173..e1c30ec 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
 VERSION?=$(shell cat VERSION)
-IMAGE_NAMESPACE?=argoprojlabs
+IMAGE_NAMESPACE?=argoproj
 IMAGE_NAME?=argocd-applicationset
 IMAGE_TAG?=latest
-CONTAINER_REGISTRY?=
+CONTAINER_REGISTRY?=quay.io
 
 MKDOCS_DOCKER_IMAGE?=squidfunk/mkdocs-material:4.1.1
 MKDOCS_RUN_ARGS?=
@@ -57,7 +57,7 @@ deploy: kustomize manifests
 .PHONY: manifests
 manifests: kustomize generate
 	$(CONTROLLER_GEN) crd:crdVersions=v1 paths="./..." output:crd:artifacts:config=./manifests/crds/
-	KUSTOMIZE=${KUSTOMIZE} hack/generate-manifests.sh
+	KUSTOMIZE=${KUSTOMIZE} CONTAINER_REGISTRY=${CONTAINER_REGISTRY} hack/generate-manifests.sh
 
 .PHONY: lint
 lint:
diff --git a/hack/generate-manifests.sh b/hack/generate-manifests.sh
index e4bd516..15b7314 100755
--- a/hack/generate-manifests.sh
+++ b/hack/generate-manifests.sh
@@ -18,7 +18,7 @@ if [ "$CONTAINER_REGISTRY" != "" ]; then
 fi
 
 IMAGE_NAME="${IMAGE_NAME:-argocd-applicationset}"
-IMAGE_NAMESPACE="${IMAGE_NAMESPACE:-argoprojlabs}"
+IMAGE_NAMESPACE="${IMAGE_NAMESPACE:-argoproj}"
 IMAGE_TAG="${IMAGE_TAG:-}"
 
 # if the tag has not been declared, and we are on a release branch, use the VERSION file.
@@ -34,7 +34,7 @@ if [ "$IMAGE_TAG" = "" ]; then
   IMAGE_TAG=latest
 fi
 
-cd ${SRCROOT}/manifests/base && ${KUSTOMIZE} edit set image argoprojlabs/argocd-applicationset=${CONTAINER_REGISTRY}${IMAGE_NAMESPACE}/$IMAGE_NAME:${IMAGE_TAG}
+cd ${SRCROOT}/manifests/base && ${KUSTOMIZE} edit set image quay.io/argoproj/argocd-applicationset=${CONTAINER_REGISTRY}${IMAGE_NAMESPACE}/$IMAGE_NAME:${IMAGE_TAG}
 
 # Use kustomize to render 'manifests/install.yaml'
 echo "${AUTOGENMSG}" > ${TEMPFILE}
diff --git a/manifests/base/deployment.yaml b/manifests/base/deployment.yaml
index a87a3c0..9bd7386 100644
--- a/manifests/base/deployment.yaml
+++ b/manifests/base/deployment.yaml
@@ -18,7 +18,7 @@ spec:
       containers:
         - command:
             - applicationset-controller
-          image: argoprojlabs/argocd-applicationset:latest
+          image: quay.io/argoproj/argocd-applicationset:latest
           imagePullPolicy: Always
           name: argocd-applicationset-controller
           env:
diff --git a/manifests/base/kustomization.yaml b/manifests/base/kustomization.yaml
index 17704ec..903b526 100644
--- a/manifests/base/kustomization.yaml
+++ b/manifests/base/kustomization.yaml
@@ -2,8 +2,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1
 kind: Kustomization
 
 images:
-- name: argoprojlabs/argocd-applicationset
-  newName: argoprojlabs/argocd-applicationset
+- name: quay.io/argoproj/argocd-applicationset
+  newName: quay.io/argoproj/argocd-applicationset
   newTag: latest
 
 namespace: argocd
diff --git a/manifests/install-with-argo-cd.yaml b/manifests/install-with-argo-cd.yaml
index 5e0e944..2d4d2b9 100644
--- a/manifests/install-with-argo-cd.yaml
+++ b/manifests/install-with-argo-cd.yaml
@@ -6185,7 +6185,7 @@ spec:
           valueFrom:
             fieldRef:
               fieldPath: metadata.namespace
-        image: argoprojlabs/argocd-applicationset:latest
+        image: quay.io/argoproj/argocd-applicationset:latest
         imagePullPolicy: Always
         name: argocd-applicationset-controller
         volumeMounts:
diff --git a/manifests/install.yaml b/manifests/install.yaml
index 1342152..044411d 100644
--- a/manifests/install.yaml
+++ b/manifests/install.yaml
@@ -3658,7 +3658,7 @@ spec:
           valueFrom:
             fieldRef:
               fieldPath: metadata.namespace
-        image: argoprojlabs/argocd-applicationset:latest
+        image: quay.io/argoproj/argocd-applicationset:latest
         imagePullPolicy: Always
         name: argocd-applicationset-controller
         volumeMounts:
diff --git a/pkg/generators/cluster.go b/pkg/generators/cluster.go
index 1e9f9ad..334e450 100644
--- a/pkg/generators/cluster.go
+++ b/pkg/generators/cluster.go
@@ -3,6 +3,8 @@ package generators
 import (
 	"context"
 	"fmt"
+	"regexp"
+	"strings"
 	"time"
 
 	"github.com/argoproj/argo-cd/util/settings"
@@ -116,7 +118,7 @@ func (g *ClusterGenerator) GenerateParams(
 	// For each matching cluster secret (non-local clusters only)
 	for _, cluster := range secretsFound {
 		params := map[string]string{}
-		params["name"] = string(cluster.Data["name"])
+		params["name"] = sanitizeName(string(cluster.Data["name"]))
 		params["server"] = string(cluster.Data["server"])
 		for key, value := range cluster.ObjectMeta.Annotations {
 			params[fmt.Sprintf("metadata.annotations.%s", key)] = value
@@ -161,3 +163,20 @@ func (g *ClusterGenerator) getSecretsByClusterName(appSetGenerator *argoprojiov1
 	return res, nil
 
 }
+
+// santize the name in accordance with the below rules
+// 1. contain no more than 253 characters
+// 2. contain only lowercase alphanumeric characters, '-' or '.'
+// 3. start and end with an alphanumeric character
+func sanitizeName(name string) string {
+	invalidDNSNameChars := regexp.MustCompile("[^-a-z0-9.]")
+	maxDNSNameLength := 253
+
+	name = strings.ToLower(name)
+	name = invalidDNSNameChars.ReplaceAllString(name, "-")
+	if len(name) > maxDNSNameLength {
+		name = name[:maxDNSNameLength]
+	}
+
+	return strings.Trim(name, "-.")
+}


Test patch:
diff --git a/pkg/generators/cluster_test.go b/pkg/generators/cluster_test.go
index 6bec3f8..ca441d3 100644
--- a/pkg/generators/cluster_test.go
+++ b/pkg/generators/cluster_test.go
@@ -241,3 +241,13 @@ func TestGenerateParams(t *testing.T) {
 		})
 	}
 }
+
+func TestSanitizeClusterName(t *testing.T) {
+	t.Run("valid DNS-1123 subdomain name", func(t *testing.T) {
+		assert.Equal(t, "cluster-name", sanitizeName("cluster-name"))
+	})
+	t.Run("invalid DNS-1123 subdomain name", func(t *testing.T) {
+		invalidName := "-.--CLUSTER/name  -./.-"
+		assert.Equal(t, "cluster-name", sanitizeName(invalidName))
+	})
+}
diff --git a/pkg/services/repo_service_test.go b/pkg/services/repo_service_test.go
index f3efac0..109ec30 100644
--- a/pkg/services/repo_service_test.go
+++ b/pkg/services/repo_service_test.go
@@ -3,6 +3,7 @@ package services
 import (
 	"context"
 	"errors"
+	"os"
 	"sort"
 	"strings"
 	"testing"
@@ -319,7 +320,7 @@ func TestGetFileContent(t *testing.T) {
 			repoURL:       "https://github.com/argoproj/argocd-example-apps/",
 			revision:      commitID,
 			path:          "/this-file-does-not-exist.md",
-			expectedError: errors.New("open /tmp/https:__github.com_argoproj_argocd-example-apps_/this-file-does-not-exist.md: no such file or directory"),
+			expectedError: errors.New("open " + os.TempDir() + "/https:__github.com_argoproj_argocd-example-apps_/this-file-does-not-exist.md: no such file or directory"),
 		},
 	}