diff --git a/integrationtests/gitjob/controller/controller_test.go b/integrationtests/gitjob/controller/controller_test.go index 3ea43799f2..8e63ca50da 100644 --- a/integrationtests/gitjob/controller/controller_test.go +++ b/integrationtests/gitjob/controller/controller_test.go @@ -24,7 +24,7 @@ import ( "github.com/rancher/wrangler/v3/pkg/genericcondition" "github.com/rancher/fleet/integrationtests/utils" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" ) @@ -86,7 +86,7 @@ var _ = Describe("GitJob controller", func() { if err != nil { return err } - jobName = name.SafeConcatName(gitRepoName, name.Hex(repo+commit, 5)) + jobName = names.SafeConcatName(gitRepoName, names.Hex(repo+commit, 5)) return k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepoNamespace}, &job) }).Should(Not(HaveOccurred())) @@ -101,7 +101,7 @@ var _ = Describe("GitJob controller", func() { // it should create RBAC resources for that gitRepo Eventually(func(g Gomega) { - saName := name.SafeConcatName("git", gitRepo.Name) + saName := names.SafeConcatName("git", gitRepo.Name) ns := types.NamespacedName{Name: saName, Namespace: gitRepo.Namespace} var sa corev1.ServiceAccount @@ -316,7 +316,7 @@ var _ = Describe("GitJob controller", func() { By("verifying that the job is deleted if Spec.Generation changed") Expect(simulateIncreaseGitRepoGeneration(gitRepo)).ToNot(HaveOccurred()) Eventually(func() bool { - jobName = name.SafeConcatName(gitRepoName, name.Hex(repo+commit, 5)) + jobName = names.SafeConcatName(gitRepoName, names.Hex(repo+commit, 5)) return errors.IsNotFound(k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepoNamespace}, &job)) }).Should(BeTrue()) }) @@ -337,7 +337,7 @@ var _ = Describe("GitJob controller", func() { By("creating a Job") Eventually(func() error { - jobName := name.SafeConcatName(gitRepoName, name.Hex(repo+commit, 5)) + jobName := names.SafeConcatName(gitRepoName, names.Hex(repo+commit, 5)) return k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepoNamespace}, &job) }).Should(Not(HaveOccurred())) }) @@ -350,7 +350,7 @@ var _ = Describe("GitJob controller", func() { const newCommit = "9ca3a0adbbba32" expectedCommit = newCommit Eventually(func() error { - jobName := name.SafeConcatName(gitRepoName, name.Hex(repo+newCommit, 5)) + jobName := names.SafeConcatName(gitRepoName, names.Hex(repo+newCommit, 5)) return k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepoNamespace}, &job) }).Should(Not(HaveOccurred())) }) @@ -370,7 +370,7 @@ var _ = Describe("GitJob controller", func() { gitRepo = createGitRepo(gitRepoName) Expect(k8sClient.Create(ctx, &gitRepo)).ToNot(HaveOccurred()) Eventually(func() error { - jobName = name.SafeConcatName(gitRepoName, name.Hex(repo+commit, 5)) + jobName = names.SafeConcatName(gitRepoName, names.Hex(repo+commit, 5)) return k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepoNamespace}, &job) }).Should(Not(HaveOccurred())) // store the generation value to compare against later @@ -443,7 +443,7 @@ var _ = Describe("GitJob controller", func() { gitRepo = createGitRepo(gitRepoName) Expect(k8sClient.Create(ctx, &gitRepo)).ToNot(HaveOccurred()) Eventually(func() error { - jobName = name.SafeConcatName(gitRepoName, name.Hex(repo+commit, 5)) + jobName = names.SafeConcatName(gitRepoName, names.Hex(repo+commit, 5)) return k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepoNamespace}, &job) }).Should(Not(HaveOccurred())) @@ -488,7 +488,7 @@ var _ = Describe("GitJob controller", func() { By("Creating a job") Eventually(func() error { - jobName := name.SafeConcatName(gitRepoName, name.Hex(repo+stableCommit, 5)) + jobName := names.SafeConcatName(gitRepoName, names.Hex(repo+stableCommit, 5)) return k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepoNamespace}, &job) }).Should(Not(HaveOccurred())) }) @@ -558,7 +558,7 @@ var _ = Describe("GitJob controller", func() { It("doesn't create RBAC resources", func() { Consistently(func() bool { - saName := name.SafeConcatName("git", gitRepo.Name) + saName := names.SafeConcatName("git", gitRepo.Name) ns := types.NamespacedName{Name: saName, Namespace: gitRepo.Namespace} if err := k8sClient.Get(ctx, ns, &corev1.ServiceAccount{}); !errors.IsNotFound(err) { @@ -576,7 +576,7 @@ var _ = Describe("GitJob controller", func() { It("doesn't create the job", func() { Consistently(func() bool { - jobName := name.SafeConcatName(gitRepoName, name.Hex(repo+commit, 5)) + jobName := names.SafeConcatName(gitRepoName, names.Hex(repo+commit, 5)) newJob := &batchv1.Job{} err := k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepo.Namespace}, newJob) return errors.IsNotFound(err) @@ -597,7 +597,7 @@ var _ = Describe("GitJob controller", func() { It("doesn't create RBAC resources", func() { Consistently(func() bool { - saName := name.SafeConcatName("git", gitRepo.Name) + saName := names.SafeConcatName("git", gitRepo.Name) ns := types.NamespacedName{Name: saName, Namespace: gitRepo.Namespace} if err := k8sClient.Get(ctx, ns, &corev1.ServiceAccount{}); !errors.IsNotFound(err) { @@ -615,7 +615,7 @@ var _ = Describe("GitJob controller", func() { It("doesn't create the job", func() { Consistently(func() bool { - jobName := name.SafeConcatName(gitRepoName, name.Hex(repo+commit, 5)) + jobName := names.SafeConcatName(gitRepoName, names.Hex(repo+commit, 5)) newJob := &batchv1.Job{} err := k8sClient.Get(ctx, types.NamespacedName{Name: jobName, Namespace: gitRepo.Namespace}, newJob) return errors.IsNotFound(err) diff --git a/internal/bundlereader/read.go b/internal/bundlereader/read.go index 26adb768ac..1b669473be 100644 --- a/internal/bundlereader/read.go +++ b/internal/bundlereader/read.go @@ -14,7 +14,7 @@ import ( "strconv" "github.com/rancher/fleet/internal/fleetyaml" - fname "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" "github.com/sirupsen/logrus" @@ -162,7 +162,7 @@ func read(ctx context.Context, name, baseDir string, bundleSpecReader io.Reader, scans = append(scans, &fleet.ImageScan{ ObjectMeta: metav1.ObjectMeta{ - Name: fname.SafeConcatName("imagescan", name, strconv.Itoa(i)), + Name: names.SafeConcatName("imagescan", name, strconv.Itoa(i)), }, Spec: scan.ImageScanSpec, }) diff --git a/internal/cmd/agent/deployer/applied/applied.go b/internal/cmd/agent/deployer/applied/applied.go index d97e2a3186..43f2e7ea9d 100644 --- a/internal/cmd/agent/deployer/applied/applied.go +++ b/internal/cmd/agent/deployer/applied/applied.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/rancher/fleet/internal/config" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" "github.com/rancher/wrangler/v3/pkg/apply" @@ -23,12 +23,12 @@ func GetSetID(bundleID, labelPrefix, labelSuffix string) string { if labelSuffix == "" { return config.AgentBootstrapConfigName } - return name.SafeConcatName(config.AgentBootstrapConfigName, labelSuffix) + return names.SafeConcatName(config.AgentBootstrapConfigName, labelSuffix) } if labelSuffix != "" { - return name.SafeConcatName(labelPrefix, bundleID, labelSuffix) + return names.SafeConcatName(labelPrefix, bundleID, labelSuffix) } - return name.SafeConcatName(labelPrefix, bundleID) + return names.SafeConcatName(labelPrefix, bundleID) } // GetLabelsAndAnnotations returns the labels and annotations, like diff --git a/internal/cmd/cli/apply/apply.go b/internal/cmd/cli/apply/apply.go index 14ce2e097a..5c55c6007f 100644 --- a/internal/cmd/cli/apply/apply.go +++ b/internal/cmd/cli/apply/apply.go @@ -18,7 +18,7 @@ import ( "github.com/rancher/fleet/internal/client" "github.com/rancher/fleet/internal/fleetyaml" "github.com/rancher/fleet/internal/manifest" - name2 "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" "github.com/rancher/fleet/internal/ociwrapper" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" @@ -216,7 +216,7 @@ func Dir(ctx context.Context, client Getter, name, baseDir string, opts *Options // The bundleID is a valid helm release name, it's used as a default if a release name is not specified in helm options. // It's also used to create the bundle name. bundleID := filepath.Join(name, baseDir) - bundleID = name2.HelmReleaseName(bundleID) + bundleID = names.HelmReleaseName(bundleID) bundle, scans, err := readBundle(ctx, bundleID, baseDir, opts) if err != nil { diff --git a/internal/cmd/controller/agentmanagement/agent/manifest.go b/internal/cmd/controller/agentmanagement/agent/manifest.go index 5a5e9d9a45..766c66b864 100644 --- a/internal/cmd/controller/agentmanagement/agent/manifest.go +++ b/internal/cmd/controller/agentmanagement/agent/manifest.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" "github.com/rancher/fleet/internal/config" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -61,7 +61,7 @@ func Manifest(namespace string, agentScope string, opts ManifestOptions) []runti clusterRole := []runtime.Object{ &rbacv1.ClusterRole{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(admin.Namespace, admin.Name, "role"), + Name: names.SafeConcatName(admin.Namespace, admin.Name, "role"), }, Rules: []rbacv1.PolicyRule{ { @@ -77,7 +77,7 @@ func Manifest(namespace string, agentScope string, opts ManifestOptions) []runti }, &rbacv1.ClusterRoleBinding{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(admin.Namespace, admin.Name, "role", "binding"), + Name: names.SafeConcatName(admin.Namespace, admin.Name, "role", "binding"), }, Subjects: []rbacv1.Subject{ { @@ -89,7 +89,7 @@ func Manifest(namespace string, agentScope string, opts ManifestOptions) []runti RoleRef: rbacv1.RoleRef{ APIGroup: rbacv1.GroupName, Kind: "ClusterRole", - Name: name.SafeConcatName(admin.Namespace, admin.Name, "role"), + Name: names.SafeConcatName(admin.Namespace, admin.Name, "role"), }, }, } diff --git a/internal/cmd/controller/agentmanagement/controllers/cluster/controller.go b/internal/cmd/controller/agentmanagement/controllers/cluster/controller.go index 89ffafdf47..b395c26cef 100644 --- a/internal/cmd/controller/agentmanagement/controllers/cluster/controller.go +++ b/internal/cmd/controller/agentmanagement/controllers/cluster/controller.go @@ -6,7 +6,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1" @@ -99,10 +99,10 @@ func (h *handler) findClusters(namespaces corecontrollers.NamespaceCache) relate // for a given cluster name, e.g.: // "cluster-fleet-local-cluster-294db1acfa77-d9ccf852678f" func clusterNamespace(clusterNamespace, clusterName string) string { - return name.SafeConcatName("cluster", + return names.SafeConcatName("cluster", clusterNamespace, clusterName, - name.KeyHash(clusterNamespace+"::"+clusterName)) + names.KeyHash(clusterNamespace+"::"+clusterName)) } func (h *handler) OnClusterChanged(cluster *fleet.Cluster, status fleet.ClusterStatus) (fleet.ClusterStatus, error) { diff --git a/internal/cmd/controller/agentmanagement/controllers/cluster/import.go b/internal/cmd/controller/agentmanagement/controllers/cluster/import.go index 13a3d95864..9e2201b20b 100644 --- a/internal/cmd/controller/agentmanagement/controllers/cluster/import.go +++ b/internal/cmd/controller/agentmanagement/controllers/cluster/import.go @@ -18,7 +18,7 @@ import ( "github.com/rancher/fleet/internal/cmd/controller/agentmanagement/controllers/manageagent" fleetns "github.com/rancher/fleet/internal/cmd/controller/namespace" "github.com/rancher/fleet/internal/config" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" "github.com/rancher/fleet/pkg/durations" fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1" @@ -179,7 +179,7 @@ func (i *importHandler) OnChange(key string, cluster *fleet.Cluster) (_ *fleet.C } func (i *importHandler) deleteOldAgentBundle(cluster *fleet.Cluster) error { - if err := i.bundleClient.Delete(cluster.Namespace, name.SafeConcatName(manageagent.AgentBundleName, cluster.Name), nil); err != nil { + if err := i.bundleClient.Delete(cluster.Namespace, names.SafeConcatName(manageagent.AgentBundleName, cluster.Name), nil); err != nil { return err } i.namespaceController.Enqueue(cluster.Namespace) @@ -271,7 +271,7 @@ func (i *importHandler) importCluster(cluster *fleet.Cluster, status fleet.Clust setID := applied.GetSetID(config.AgentBootstrapConfigName, "", cluster.Spec.AgentNamespace) apply = apply.WithDynamicLookup().WithSetID(setID).WithNoDeleteGVK(fleetns.GVK()) - tokenName := name.SafeConcatName(ImportTokenPrefix + cluster.Name) + tokenName := names.SafeConcatName(ImportTokenPrefix + cluster.Name) token, err := i.tokens.Get(cluster.Namespace, tokenName) if err != nil { // ignore error diff --git a/internal/cmd/controller/agentmanagement/controllers/clusterregistration/controller.go b/internal/cmd/controller/agentmanagement/controllers/clusterregistration/controller.go index a0c087973c..29955336d4 100644 --- a/internal/cmd/controller/agentmanagement/controllers/clusterregistration/controller.go +++ b/internal/cmd/controller/agentmanagement/controllers/clusterregistration/controller.go @@ -14,7 +14,7 @@ import ( "github.com/rancher/fleet/internal/cmd/controller/agentmanagement/controllers/resources" secretutil "github.com/rancher/fleet/internal/cmd/controller/agentmanagement/secret" "github.com/rancher/fleet/internal/config" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" "github.com/rancher/fleet/internal/registration" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" "github.com/rancher/fleet/pkg/durations" @@ -197,7 +197,7 @@ func (h *handler) OnChange(request *fleet.ClusterRegistration, status fleet.Clus } } - saName := name.SafeConcatName(request.Name, string(request.UID)) + saName := names.SafeConcatName(request.Name, string(request.UID)) sa, err := h.serviceAccountCache.Get(cluster.Status.Namespace, saName) if err != nil && apierrors.IsNotFound(err) { // create request service account if missing @@ -311,7 +311,7 @@ func (h *handler) OnChange(request *fleet.ClusterRegistration, status fleet.Clus // starts &rbacv1.ClusterRoleBinding{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(request.Name, "content"), + Name: names.SafeConcatName(request.Name, "content"), Labels: map[string]string{ fleet.ManagedLabel: "true", }, @@ -348,7 +348,7 @@ func (h *handler) createOrGetCluster(request *fleet.ClusterRegistration) (*fleet return nil, err } - clusterName := name.SafeConcatName("cluster", name.KeyHash(request.Spec.ClientID)) + clusterName := names.SafeConcatName("cluster", names.KeyHash(request.Spec.ClientID)) if cluster, err := h.clusterCache.Get(request.Namespace, clusterName); !apierrors.IsNotFound(err) { if cluster.Spec.ClientID != request.Spec.ClientID { // This would happen with a hash collision diff --git a/internal/cmd/controller/agentmanagement/controllers/clusterregistrationtoken/handler.go b/internal/cmd/controller/agentmanagement/controllers/clusterregistrationtoken/handler.go index 74049e5eda..d62b1fe0ab 100644 --- a/internal/cmd/controller/agentmanagement/controllers/clusterregistrationtoken/handler.go +++ b/internal/cmd/controller/agentmanagement/controllers/clusterregistrationtoken/handler.go @@ -11,7 +11,7 @@ import ( secretutil "github.com/rancher/fleet/internal/cmd/controller/agentmanagement/secret" "github.com/rancher/fleet/internal/config" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1" @@ -75,7 +75,7 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C logrus.Debugf("Cluster registration token '%s/%s', creating import service account, roles and secret", token.Namespace, token.Name) var ( - saName = name.SafeConcatName(token.Name, string(token.UID)) + saName = names.SafeConcatName(token.Name, string(token.UID)) secrets []runtime.Object ) status.SecretName = "" @@ -144,7 +144,7 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C }, &rbacv1.Role{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(saName, "role"), + Name: names.SafeConcatName(saName, "role"), Namespace: token.Namespace, Labels: map[string]string{ fleet.ManagedLabel: "true", @@ -160,7 +160,7 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C }, &rbacv1.RoleBinding{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(saName, "to", "role"), + Name: names.SafeConcatName(saName, "to", "role"), Namespace: token.Namespace, Labels: map[string]string{ fleet.ManagedLabel: "true", @@ -176,12 +176,12 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C RoleRef: rbacv1.RoleRef{ APIGroup: rbacv1.GroupName, Kind: "Role", - Name: name.SafeConcatName(saName, "role"), + Name: names.SafeConcatName(saName, "role"), }, }, &rbacv1.Role{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(saName, "creds"), + Name: names.SafeConcatName(saName, "creds"), Namespace: h.systemRegistrationNamespace, }, Rules: []rbacv1.PolicyRule{ @@ -194,7 +194,7 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C }, &rbacv1.RoleBinding{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(saName, "creds"), + Name: names.SafeConcatName(saName, "creds"), Namespace: h.systemRegistrationNamespace, }, Subjects: []rbacv1.Subject{ @@ -207,7 +207,7 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C RoleRef: rbacv1.RoleRef{ APIGroup: rbacv1.GroupName, Kind: "Role", - Name: name.SafeConcatName(saName, "creds"), + Name: names.SafeConcatName(saName, "creds"), }, }, }, secrets...), status, nil diff --git a/internal/cmd/controller/agentmanagement/controllers/manageagent/manageagent.go b/internal/cmd/controller/agentmanagement/controllers/manageagent/manageagent.go index bf9a242f7e..b89d1622d4 100644 --- a/internal/cmd/controller/agentmanagement/controllers/manageagent/manageagent.go +++ b/internal/cmd/controller/agentmanagement/controllers/manageagent/manageagent.go @@ -16,7 +16,7 @@ import ( "github.com/rancher/fleet/internal/cmd/controller/agentmanagement/agent" "github.com/rancher/fleet/internal/config" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1" @@ -202,7 +202,7 @@ func (h *handler) updateClusterStatus(cluster *fleet.Cluster, status fleet.Clust func (h *handler) resolveNS(namespace, _ string, obj runtime.Object) ([]relatedresource.Key, error) { if cluster, ok := obj.(*fleet.Cluster); ok { - if _, err := h.bundleCache.Get(namespace, name.SafeConcatName(AgentBundleName, cluster.Name)); err != nil { + if _, err := h.bundleCache.Get(namespace, names.SafeConcatName(AgentBundleName, cluster.Name)); err != nil { return []relatedresource.Key{{Name: namespace}}, nil } } @@ -280,7 +280,7 @@ func (h *handler) newAgentBundle(ns string, cluster *fleet.Cluster) (runtime.Obj return &fleet.Bundle{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(AgentBundleName, cluster.Name), + Name: names.SafeConcatName(AgentBundleName, cluster.Name), Namespace: ns, }, Spec: fleet.BundleSpec{ diff --git a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go index 629cc3b59b..54709c3f02 100644 --- a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go +++ b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go @@ -17,7 +17,7 @@ import ( "github.com/rancher/fleet/internal/cmd/controller/grutil" "github.com/rancher/fleet/internal/cmd/controller/imagescan" "github.com/rancher/fleet/internal/metrics" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" "github.com/rancher/fleet/internal/ociwrapper" v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" fleetevent "github.com/rancher/fleet/pkg/event" @@ -351,7 +351,7 @@ func (r *GitJobReconciler) addGitRepoFinalizer(ctx context.Context, nsName types func (r *GitJobReconciler) createJobRBAC(ctx context.Context, gitrepo *v1alpha1.GitRepo) error { // No update needed, values are the same. So we ignore AlreadyExists. - saName := name.SafeConcatName("git", gitrepo.Name) + saName := names.SafeConcatName("git", gitrepo.Name) sa := grutil.NewServiceAccount(gitrepo.Namespace, saName) if err := controllerutil.SetControllerReference(gitrepo, sa, r.Scheme); err != nil { return err @@ -487,7 +487,7 @@ func generationChanged(r *v1alpha1.GitRepo) bool { } func jobName(obj *v1alpha1.GitRepo) string { - return name.SafeConcatName(obj.Name, name.Hex(obj.Spec.Repo+obj.Status.Commit, 5)) + return names.SafeConcatName(obj.Name, names.Hex(obj.Spec.Repo+obj.Status.Commit, 5)) } func caBundleName(obj *v1alpha1.GitRepo) string { @@ -644,7 +644,7 @@ func (r *GitJobReconciler) newJobSpec(ctx context.Context, gitrepo *v1alpha1.Git } } - saName := name.SafeConcatName("git", gitrepo.Name) + saName := names.SafeConcatName("git", gitrepo.Name) logger := log.FromContext(ctx) args, envs := argsAndEnvs(gitrepo, logger.V(1).Enabled()) diff --git a/internal/cmd/controller/grutil/targetsyaml.go b/internal/cmd/controller/grutil/targetsyaml.go index 4922fd3fac..894abd9dec 100644 --- a/internal/cmd/controller/grutil/targetsyaml.go +++ b/internal/cmd/controller/grutil/targetsyaml.go @@ -3,7 +3,7 @@ package grutil import ( "encoding/json" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" corev1 "k8s.io/api/core/v1" @@ -31,10 +31,10 @@ func NewTargetsConfigMap(repo *fleet.GitRepo) (*corev1.ConfigMap, error) { return nil, err } - hash := name.KeyHash(string(data)) + hash := names.KeyHash(string(data)) return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: name.SafeConcatName(repo.Name, "config", hash), + Name: names.SafeConcatName(repo.Name, "config", hash), Namespace: repo.Namespace, }, BinaryData: map[string][]byte{ diff --git a/internal/helmdeployer/deployer.go b/internal/helmdeployer/deployer.go index 1ad85ca5b7..6a46990c88 100644 --- a/internal/helmdeployer/deployer.go +++ b/internal/helmdeployer/deployer.go @@ -12,7 +12,7 @@ import ( "helm.sh/helm/v3/pkg/storage" "helm.sh/helm/v3/pkg/storage/driver" - name2 "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" "k8s.io/apimachinery/pkg/runtime" @@ -119,7 +119,7 @@ func (h *Helm) getOpts(bundleID string, options fleet.BundleDeploymentOptions) ( // releaseName has a limit of 53 in helm https://github.com/helm/helm/blob/main/pkg/action/install.go#L58 // fleet apply already produces valid names, but we need to make sure // that bundles from other sources are valid - return timeout, ns, name2.HelmReleaseName(bundleID) + return timeout, ns, names.HelmReleaseName(bundleID) } func (h *Helm) getCfg(ctx context.Context, namespace, serviceAccountName string) (action.Configuration, error) { diff --git a/internal/name/keyhash.go b/internal/names/keyhash.go similarity index 95% rename from internal/name/keyhash.go rename to internal/names/keyhash.go index c6dfa6fccb..2abac59f97 100644 --- a/internal/name/keyhash.go +++ b/internal/names/keyhash.go @@ -1,4 +1,4 @@ -package name +package names import ( "crypto/sha256" diff --git a/internal/name/name.go b/internal/names/name.go similarity index 96% rename from internal/name/name.go rename to internal/names/name.go index 69cd248c8c..1c6bfc1145 100644 --- a/internal/name/name.go +++ b/internal/names/name.go @@ -1,5 +1,5 @@ -// Package name provides functions for truncating and hashing strings and for generating valid k8s resource names. -package name +// Package names provides functions for truncating and hashing strings and for generating valid k8s resource names. +package names import ( "crypto/md5" // nolint:gosec // Non-crypto use diff --git a/internal/name/name_test.go b/internal/names/name_test.go similarity index 93% rename from internal/name/name_test.go rename to internal/names/name_test.go index c6b1dcabcb..fbdf23a162 100644 --- a/internal/name/name_test.go +++ b/internal/names/name_test.go @@ -1,9 +1,9 @@ -package name_test +package names_test import ( "fmt" - "github.com/rancher/fleet/internal/name" + "github.com/rancher/fleet/internal/names" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -36,7 +36,7 @@ var _ = Describe("Name", func() { It("matches expected results", func() { for _, t := range tests { - r := name.Limit(t.arg, t.n) + r := names.Limit(t.arg, t.n) Expect(r).To(Equal(t.result), fmt.Sprintf("%#v", t)) } }) @@ -58,7 +58,7 @@ var _ = Describe("Name", func() { It("matches expected results", func() { for _, t := range tests { - r := name.HelmReleaseName(t.arg) + r := names.HelmReleaseName(t.arg) Expect(r).To(Equal(t.result), fmt.Sprintf("%#v", t)) } }) diff --git a/internal/name/safeconcat.go b/internal/names/safeconcat.go similarity index 98% rename from internal/name/safeconcat.go rename to internal/names/safeconcat.go index 8929199e03..8b83386f96 100644 --- a/internal/name/safeconcat.go +++ b/internal/names/safeconcat.go @@ -1,4 +1,4 @@ -package name +package names import ( "crypto/sha256" diff --git a/internal/name/safeconcat_test.go b/internal/names/safeconcat_test.go similarity index 99% rename from internal/name/safeconcat_test.go rename to internal/names/safeconcat_test.go index aeefc1d975..5bbdee6205 100644 --- a/internal/name/safeconcat_test.go +++ b/internal/names/safeconcat_test.go @@ -1,4 +1,4 @@ -package name +package names import ( "testing" diff --git a/internal/name/suite_test.go b/internal/names/suite_test.go similarity index 90% rename from internal/name/suite_test.go rename to internal/names/suite_test.go index 7db1aa7dbe..e8243f7f33 100644 --- a/internal/name/suite_test.go +++ b/internal/names/suite_test.go @@ -1,4 +1,4 @@ -package name_test +package names_test import ( "testing"