From 6415f7b95fc40de6795a8d9c2afacb0c189d728c Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Thu, 2 Jan 2025 11:08:11 +0100 Subject: [PATCH] Rename package entity to types Signed-off-by: cmoulliard --- pkg/cmd/get/clusters.go | 18 +++++++++--------- pkg/cmd/get/packages.go | 6 +++--- pkg/cmd/get/secrets.go | 12 ++++++------ pkg/cmd/get/secrets_test.go | 10 +++++----- pkg/printer/cluster.go | 8 ++++---- pkg/printer/package.go | 6 +++--- pkg/printer/secret.go | 6 +++--- pkg/{entity => types}/allocated.go | 2 +- pkg/{entity => types}/capacity.go | 2 +- pkg/{entity => types}/cluster.go | 2 +- pkg/{entity => types}/node.go | 2 +- pkg/{entity => types}/package.go | 2 +- pkg/{entity => types}/secret.go | 2 +- 13 files changed, 39 insertions(+), 39 deletions(-) rename pkg/{entity => types}/allocated.go (79%) rename pkg/{entity => types}/capacity.go (82%) rename pkg/{entity => types}/cluster.go (90%) rename pkg/{entity => types}/node.go (89%) rename pkg/{entity => types}/package.go (90%) rename pkg/{entity => types}/secret.go (95%) diff --git a/pkg/cmd/get/clusters.go b/pkg/cmd/get/clusters.go index 22a13be2..3e6bb49e 100644 --- a/pkg/cmd/get/clusters.go +++ b/pkg/cmd/get/clusters.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/cnoe-io/idpbuilder/api/v1alpha1" "github.com/cnoe-io/idpbuilder/pkg/cmd/helpers" - "github.com/cnoe-io/idpbuilder/pkg/entity" "github.com/cnoe-io/idpbuilder/pkg/k8s" "github.com/cnoe-io/idpbuilder/pkg/kind" "github.com/cnoe-io/idpbuilder/pkg/printer" + idpTypes "github.com/cnoe-io/idpbuilder/pkg/types" "github.com/cnoe-io/idpbuilder/pkg/util" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" @@ -55,7 +55,7 @@ func list(cmd *cobra.Command, args []string) error { } } -func populateClusterList() ([]entity.Cluster, error) { +func populateClusterList() ([]idpTypes.Cluster, error) { logger := helpers.CmdLogger detectOpt, err := util.DetectKindNodeProvider() @@ -81,7 +81,7 @@ func populateClusterList() ([]entity.Cluster, error) { } // Create an empty array of clusters to collect the information - clusterList := []entity.Cluster{} + clusterList := []idpTypes.Cluster{} // List the idp builder clusters according to the provider: podman or docker provider := cluster.NewProvider(cluster.ProviderWithLogger(kind.KindLoggerFromLogr(&logger)), detectOpt) @@ -97,7 +97,7 @@ func populateClusterList() ([]entity.Cluster, error) { } for _, cluster := range clusters { - aCluster := entity.Cluster{Name: cluster} + aCluster := idpTypes.Cluster{Name: cluster} // Search about the idp cluster within the kubeconfig file and show information c, found := findClusterByName(config, "kind-"+cluster) @@ -139,7 +139,7 @@ func populateClusterList() ([]entity.Cluster, error) { for _, node := range nodeList.Items { nodeName := node.Name - aNode := entity.Node{} + aNode := idpTypes.Node{} aNode.Name = nodeName for _, addr := range node.Status.Addresses { @@ -158,7 +158,7 @@ func populateClusterList() ([]entity.Cluster, error) { cpu := resources[corev1.ResourceCPU] pods := resources[corev1.ResourcePods] - aNode.Capacity = entity.Capacity{ + aNode.Capacity = idpTypes.Capacity{ Memory: float64(memory.Value()) / (1024 * 1024 * 1024), Cpu: cpu.Value(), Pods: pods.Value(), @@ -181,11 +181,11 @@ func populateClusterList() ([]entity.Cluster, error) { return clusterList, nil } -func printAllocatedResources(ctx context.Context, k8sClient client.Client, nodeName string) (entity.Allocated, error) { +func printAllocatedResources(ctx context.Context, k8sClient client.Client, nodeName string) (idpTypes.Allocated, error) { // List all pods on the specified node var podList corev1.PodList if err := k8sClient.List(ctx, &podList, client.MatchingFields{"spec.nodeName": nodeName}); err != nil { - return entity.Allocated{}, fmt.Errorf("failed to list pods on node %s.", nodeName) + return idpTypes.Allocated{}, fmt.Errorf("failed to list pods on node %s.", nodeName) } // Initialize counters for CPU and memory requests @@ -204,7 +204,7 @@ func printAllocatedResources(ctx context.Context, k8sClient client.Client, nodeN } } - allocated := entity.Allocated{ + allocated := idpTypes.Allocated{ Memory: totalMemory.String(), Cpu: totalCPU.String(), } diff --git a/pkg/cmd/get/packages.go b/pkg/cmd/get/packages.go index e4b70c77..902cbd6c 100644 --- a/pkg/cmd/get/packages.go +++ b/pkg/cmd/get/packages.go @@ -5,9 +5,9 @@ import ( "fmt" "github.com/cnoe-io/idpbuilder/api/v1alpha1" "github.com/cnoe-io/idpbuilder/pkg/build" - "github.com/cnoe-io/idpbuilder/pkg/entity" "github.com/cnoe-io/idpbuilder/pkg/k8s" "github.com/cnoe-io/idpbuilder/pkg/printer" + "github.com/cnoe-io/idpbuilder/pkg/types" "github.com/spf13/cobra" "io" "k8s.io/client-go/util/homedir" @@ -53,7 +53,7 @@ func getPackagesE(cmd *cobra.Command, args []string) error { // Print all the custom packages or based on package arguments passed using flag: -p func printPackages(ctx context.Context, outWriter io.Writer, kubeClient client.Client, format string) error { - packageList := []entity.Package{} + packageList := []types.Package{} customPackages := v1alpha1.CustomPackageList{} var err error @@ -81,7 +81,7 @@ func printPackages(ctx context.Context, outWriter io.Writer, kubeClient client.C } for _, cp := range customPackages.Items { - newPackage := entity.Package{} + newPackage := types.Package{} newPackage.Name = cp.Name newPackage.Namespace = cp.Namespace // There is a GitRepositoryRefs when the project has been cloned to the internal git repository diff --git a/pkg/cmd/get/secrets.go b/pkg/cmd/get/secrets.go index e731b24c..2f4ad6b5 100644 --- a/pkg/cmd/get/secrets.go +++ b/pkg/cmd/get/secrets.go @@ -3,8 +3,8 @@ package get import ( "context" "fmt" - "github.com/cnoe-io/idpbuilder/pkg/entity" "github.com/cnoe-io/idpbuilder/pkg/printer" + "github.com/cnoe-io/idpbuilder/pkg/types" "io" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "os" @@ -83,7 +83,7 @@ func getSecretsE(cmd *cobra.Command, args []string) error { func printAllPackageSecrets(ctx context.Context, outWriter io.Writer, kubeClient client.Client, format string) error { selector := labels.NewSelector() - secrets := []entity.Secret{} + secrets := []types.Secret{} secretPrinter := printer.SecretPrinter{ Secrets: secrets, OutWriter: outWriter, @@ -122,7 +122,7 @@ func printAllPackageSecrets(ctx context.Context, outWriter io.Writer, kubeClient func printPackageSecrets(ctx context.Context, outWriter io.Writer, kubeClient client.Client, format string) error { selector := labels.NewSelector() - secrets := []entity.Secret{} + secrets := []types.Secret{} secretPrinter := printer.SecretPrinter{ OutWriter: outWriter, } @@ -170,7 +170,7 @@ func printPackageSecrets(ctx context.Context, outWriter io.Writer, kubeClient cl return secretPrinter.PrintOutput(format) } -func generateSecretTable(secretTable []entity.Secret) metav1.Table { +func generateSecretTable(secretTable []types.Secret) metav1.Table { table := &metav1.Table{} table.ColumnDefinitions = []metav1.TableColumnDefinition{ {Name: "Name", Type: "string"}, @@ -204,8 +204,8 @@ func generateSecretTable(secretTable []entity.Secret) metav1.Table { return *table } -func populateSecret(s v1.Secret, isCoreSecret bool) entity.Secret { - secret := entity.Secret{ +func populateSecret(s v1.Secret, isCoreSecret bool) types.Secret { + secret := types.Secret{ Name: s.Name, Namespace: s.Namespace, } diff --git a/pkg/cmd/get/secrets_test.go b/pkg/cmd/get/secrets_test.go index 07842c1c..b8ab7c3f 100644 --- a/pkg/cmd/get/secrets_test.go +++ b/pkg/cmd/get/secrets_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/cnoe-io/idpbuilder/api/v1alpha1" - "github.com/cnoe-io/idpbuilder/pkg/entity" + "github.com/cnoe-io/idpbuilder/pkg/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" v1 "k8s.io/api/core/v1" @@ -145,7 +145,7 @@ func TestOutput(t *testing.T) { ctx := context.Background() r, _ := labels.NewRequirement(v1alpha1.CLISecretLabelKey, selection.Equals, []string{v1alpha1.CLISecretLabelValue}) - corePkgData := map[string]entity.Secret{ + corePkgData := map[string]types.Secret{ argoCDInitialAdminSecretName: { IsCore: true, Name: argoCDInitialAdminSecretName, @@ -162,7 +162,7 @@ func TestOutput(t *testing.T) { }, } - packageData := map[string]entity.Secret{ + packageData := map[string]types.Secret{ "name1": { Name: "name1", Namespace: "ns1", @@ -216,7 +216,7 @@ func TestOutput(t *testing.T) { assert.Nil(t, err) // verify received json data - var received []entity.Secret + var received []types.Secret err = json.Unmarshal(buffer.Bytes(), &received) assert.Nil(t, err) assert.Equal(t, 4, len(received)) @@ -244,7 +244,7 @@ func TestOutput(t *testing.T) { assert.Equal(t, 0, len(packageData)) } -func secretDataToSecret(data entity.Secret) v1.Secret { +func secretDataToSecret(data types.Secret) v1.Secret { d := make(map[string][]byte) if data.IsCore { d["username"] = []byte(data.Username) diff --git a/pkg/printer/cluster.go b/pkg/printer/cluster.go index 4ebd4c55..7e4dfdf4 100644 --- a/pkg/printer/cluster.go +++ b/pkg/printer/cluster.go @@ -2,13 +2,13 @@ package printer import ( "fmt" - "github.com/cnoe-io/idpbuilder/pkg/entity" + "github.com/cnoe-io/idpbuilder/pkg/types" "io" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) type ClusterPrinter struct { - Clusters []entity.Cluster + Clusters []types.Cluster OutWriter io.Writer } @@ -25,7 +25,7 @@ func (cp ClusterPrinter) PrintOutput(format string) error { } } -func generateClusterTable(input []entity.Cluster) metav1.Table { +func generateClusterTable(input []types.Cluster) metav1.Table { table := &metav1.Table{} table.ColumnDefinitions = []metav1.TableColumnDefinition{ {Name: "Name", Type: "string"}, @@ -52,7 +52,7 @@ func generateClusterTable(input []entity.Cluster) metav1.Table { return *table } -func generateNodeData(nodes []entity.Node) string { +func generateNodeData(nodes []types.Node) string { var result string for i, aNode := range nodes { result += aNode.Name diff --git a/pkg/printer/package.go b/pkg/printer/package.go index a86b8a8d..907bb8d4 100644 --- a/pkg/printer/package.go +++ b/pkg/printer/package.go @@ -2,13 +2,13 @@ package printer import ( "fmt" - "github.com/cnoe-io/idpbuilder/pkg/entity" + "github.com/cnoe-io/idpbuilder/pkg/types" "io" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) type PackagePrinter struct { - Packages []entity.Package + Packages []types.Package OutWriter io.Writer } @@ -25,7 +25,7 @@ func (pp PackagePrinter) PrintOutput(format string) error { } } -func generatePackageTable(packagesTable []entity.Package) metav1.Table { +func generatePackageTable(packagesTable []types.Package) metav1.Table { table := &metav1.Table{} table.ColumnDefinitions = []metav1.TableColumnDefinition{ {Name: "Custom package name", Type: "string"}, diff --git a/pkg/printer/secret.go b/pkg/printer/secret.go index 425f961d..eff52856 100644 --- a/pkg/printer/secret.go +++ b/pkg/printer/secret.go @@ -2,14 +2,14 @@ package printer import ( "fmt" - "github.com/cnoe-io/idpbuilder/pkg/entity" + "github.com/cnoe-io/idpbuilder/pkg/types" "io" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "strings" ) type SecretPrinter struct { - Secrets []entity.Secret + Secrets []types.Secret OutWriter io.Writer } @@ -26,7 +26,7 @@ func (sp SecretPrinter) PrintOutput(format string) error { } } -func generateSecretTable(secretTable []entity.Secret) metav1.Table { +func generateSecretTable(secretTable []types.Secret) metav1.Table { table := &metav1.Table{} table.ColumnDefinitions = []metav1.TableColumnDefinition{ {Name: "Name", Type: "string"}, diff --git a/pkg/entity/allocated.go b/pkg/types/allocated.go similarity index 79% rename from pkg/entity/allocated.go rename to pkg/types/allocated.go index 297f024b..c895cd0a 100644 --- a/pkg/entity/allocated.go +++ b/pkg/types/allocated.go @@ -1,4 +1,4 @@ -package entity +package types type Allocated struct { Cpu string diff --git a/pkg/entity/capacity.go b/pkg/types/capacity.go similarity index 82% rename from pkg/entity/capacity.go rename to pkg/types/capacity.go index cbe910dd..5a3db56e 100644 --- a/pkg/entity/capacity.go +++ b/pkg/types/capacity.go @@ -1,4 +1,4 @@ -package entity +package types type Capacity struct { Memory float64 diff --git a/pkg/entity/cluster.go b/pkg/types/cluster.go similarity index 90% rename from pkg/entity/cluster.go rename to pkg/types/cluster.go index 582e29c0..b73f9a98 100644 --- a/pkg/entity/cluster.go +++ b/pkg/types/cluster.go @@ -1,4 +1,4 @@ -package entity +package types type Cluster struct { Name string diff --git a/pkg/entity/node.go b/pkg/types/node.go similarity index 89% rename from pkg/entity/node.go rename to pkg/types/node.go index 7d07d5a6..cd6a0635 100644 --- a/pkg/entity/node.go +++ b/pkg/types/node.go @@ -1,4 +1,4 @@ -package entity +package types type Node struct { Name string diff --git a/pkg/entity/package.go b/pkg/types/package.go similarity index 90% rename from pkg/entity/package.go rename to pkg/types/package.go index b4acee6c..98753679 100644 --- a/pkg/entity/package.go +++ b/pkg/types/package.go @@ -1,4 +1,4 @@ -package entity +package types type Package struct { Name string diff --git a/pkg/entity/secret.go b/pkg/types/secret.go similarity index 95% rename from pkg/entity/secret.go rename to pkg/types/secret.go index f7c2b53a..0608b328 100644 --- a/pkg/entity/secret.go +++ b/pkg/types/secret.go @@ -1,4 +1,4 @@ -package entity +package types type Secret struct { IsCore bool