Skip to content

Commit

Permalink
Rename name package to names
Browse files Browse the repository at this point in the history
  • Loading branch information
manno committed Sep 23, 2024
1 parent bd7d811 commit 0ac6288
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 65 deletions.
26 changes: 13 additions & 13 deletions integrationtests/gitjob/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()))

Expand All @@ -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
Expand Down Expand Up @@ -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())
})
Expand All @@ -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()))
})
Expand All @@ -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()))
})
Expand All @@ -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
Expand Down Expand Up @@ -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()))

Expand Down Expand Up @@ -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()))
})
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/bundlereader/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
})
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/agent/deployer/applied/applied.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/cli/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/controller/agentmanagement/agent/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
{
Expand All @@ -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{
{
Expand All @@ -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"),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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{
Expand Down
Loading

0 comments on commit 0ac6288

Please sign in to comment.