Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed names.NewRandomK8() from the project completely #580

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions pkg/builder/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"time"

batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/celestiaorg/knuu/pkg/builder"
"github.com/celestiaorg/knuu/pkg/names"
"github.com/celestiaorg/knuu/pkg/system"
)

Expand Down Expand Up @@ -133,10 +133,7 @@ func (k *Kaniko) containerLogs(ctx context.Context, pod *v1.Pod) (string, error)
}

func (k *Kaniko) prepareJob(ctx context.Context, b *builder.BuilderOptions) (*batchv1.Job, error) {
jobName, err := names.NewRandomK8(kanikoJobNamePrefix)
if err != nil {
return nil, ErrGeneratingUUID.Wrap(err)
}
jobName := fmt.Sprintf("%s-%d", kanikoJobNamePrefix, time.Now().UnixNano())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still random from the perspective that the user is not defining the name.

The intention behind the issue is that all names should be explicitly set by the user so that they have knowledge of them in order to reference and update things.


ephemeralStorage, err := resource.ParseQuantity(EphemeralStorage)
if err != nil {
Expand Down
8 changes: 2 additions & 6 deletions pkg/instance/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/resource"

"github.com/celestiaorg/knuu/pkg/k8s"
"github.com/celestiaorg/knuu/pkg/names"
)

type storage struct {
Expand Down Expand Up @@ -101,7 +101,6 @@ func (s *storage) AddFolder(src string, dest string, chown string) error {
// copy file to destination path
return s.AddFile(path, filepath.Join(dest, relPath), chown)
})

if err != nil {
return ErrCopyingFolderToInstance.WithParams(src, s.instance.name).Wrap(err)
}
Expand Down Expand Up @@ -377,10 +376,7 @@ func (s *storage) readFileFromImage(ctx context.Context, filePath string) ([]byt
// extract the file from them, but it seems hacky and will run on the user's machine.
// Therefore, we will use the tmp instance to get the file from the image

tmpName, err := names.NewRandomK8("tmp-dl")
if err != nil {
return nil, err
}
tmpName := fmt.Sprintf("tmp-%d", time.Now().UnixNano())

ti, err := New(tmpName, s.instance.SystemDependencies)
if err != nil {
Expand Down
16 changes: 0 additions & 16 deletions pkg/names/names.go

This file was deleted.

26 changes: 6 additions & 20 deletions pkg/traefik/traefik.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"k8s.io/utils/ptr"

"github.com/celestiaorg/knuu/pkg/k8s"
"github.com/celestiaorg/knuu/pkg/names"
)

const (
Expand Down Expand Up @@ -52,21 +51,15 @@ func (t *Traefik) Deploy(ctx context.Context) error {
}

// Create a dedicated service account for Traefik
serviceAccountName, err := names.NewRandomK8("traefik-service-account")
if err != nil {
return err
}
serviceAccountName := fmt.Sprintf("traefik-service-account-%d", time.Now().UnixNano())
if err := t.K8sClient.CreateServiceAccount(ctx, serviceAccountName, nil); err != nil {
return ErrFailedToCreateServiceAccount.Wrap(err)
}

clusterRoleName, err := names.NewRandomK8(roleName)
if err != nil {
return err
}
clusterRoleName := fmt.Sprintf("%s-%d", roleName, time.Now().UnixNano())

// Define and create a ClusterRole for Traefik
err = t.K8sClient.CreateClusterRole(ctx, clusterRoleName, nil, []rbacv1.PolicyRule{
err := t.K8sClient.CreateClusterRole(ctx, clusterRoleName, nil, []rbacv1.PolicyRule{
notlelouch marked this conversation as resolved.
Show resolved Hide resolved
{
APIGroups: []string{""}, // Core group
Resources: []string{"pods", "endpoints", "secrets", "services"},
Expand All @@ -87,7 +80,6 @@ func (t *Traefik) Deploy(ctx context.Context) error {
Verbs: []string{"get", "list", "watch"},
},
})

if err != nil {
return ErrTraefikRoleCreationFailed.Wrap(err)
}
Expand Down Expand Up @@ -209,10 +201,7 @@ func (t *Traefik) Endpoint(ctx context.Context) (string, error) {
}

func (t *Traefik) AddHost(ctx context.Context, serviceName, prefix string, portTCP int) error {
middlewareName, err := names.NewRandomK8("strip-" + prefix)
if err != nil {
return ErrGeneratingRandomK8sName.Wrap(err)
}
middlewareName := fmt.Sprintf("middleware-%d", time.Now().UnixNano())

// middleware is required to strip the prefix from the service name
if err := t.createMiddleware(ctx, prefix, middlewareName); err != nil {
Expand Down Expand Up @@ -303,10 +292,7 @@ func (t *Traefik) createIngressRoute(
Resource: "ingressroutes",
}

ingressRouteName, err := names.NewRandomK8("ing-route-" + prefix)
if err != nil {
return ErrTraefikIngressRouteCreationFailed.Wrap(err)
}
ingressRouteName := fmt.Sprintf("ing-route-%d", time.Now().UnixNano())

ingressRoute := &unstructured.Unstructured{
Object: map[string]interface{}{
Expand Down Expand Up @@ -339,7 +325,7 @@ func (t *Traefik) createIngressRoute(
},
}

_, err = t.K8sClient.DynamicClient().Resource(ingressRouteGVR).Namespace(t.K8sClient.Namespace()).
_, err := t.K8sClient.DynamicClient().Resource(ingressRouteGVR).Namespace(t.K8sClient.Namespace()).
Create(ctx, ingressRoute, metav1.CreateOptions{})
if err != nil {
return ErrTraefikIngressRouteCreationFailed.Wrap(err)
Expand Down
Loading