Skip to content

Commit

Permalink
Rename package entity to types
Browse files Browse the repository at this point in the history
Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Jan 2, 2025
1 parent cb79a78 commit 6415f7b
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 39 deletions.
18 changes: 9 additions & 9 deletions pkg/cmd/get/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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(),
Expand All @@ -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
Expand All @@ -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(),
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/get/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/get/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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,
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/get/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -162,7 +162,7 @@ func TestOutput(t *testing.T) {
},
}

packageData := map[string]entity.Secret{
packageData := map[string]types.Secret{
"name1": {
Name: "name1",
Namespace: "ns1",
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/printer/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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"},
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/printer/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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"},
Expand Down
6 changes: 3 additions & 3 deletions pkg/printer/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/allocated.go → pkg/types/allocated.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package entity
package types

type Allocated struct {
Cpu string
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/capacity.go → pkg/types/capacity.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package entity
package types

type Capacity struct {
Memory float64
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/cluster.go → pkg/types/cluster.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package entity
package types

type Cluster struct {
Name string
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/node.go → pkg/types/node.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package entity
package types

type Node struct {
Name string
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/package.go → pkg/types/package.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package entity
package types

type Package struct {
Name string
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/secret.go → pkg/types/secret.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package entity
package types

type Secret struct {
IsCore bool
Expand Down

0 comments on commit 6415f7b

Please sign in to comment.