Repository: skupperproject/skupper
Pull request #1549 (2024-07-18 18:00:06)

fix format


Patch:
diff --git a/internal/cmd/skupper/site/kube/site_create.go b/internal/cmd/skupper/site/kube/site_create.go
index cbf3b210..bf15c6c3 100644
--- a/internal/cmd/skupper/site/kube/site_create.go
+++ b/internal/cmd/skupper/site/kube/site_create.go
@@ -6,6 +6,7 @@ package kube
 import (
 	"context"
 	"fmt"
+	"k8s.io/client-go/kubernetes"
 
 	"github.com/skupperproject/skupper/internal/cmd/skupper/utils"
 	"github.com/skupperproject/skupper/internal/kube/client"
@@ -32,6 +33,7 @@ type CreateFlags struct {
 
 type CmdSiteCreate struct {
 	Client             skupperv1alpha1.SkupperV1alpha1Interface
+	KubeClient         kubernetes.Interface
 	CobraCmd           cobra.Command
 	flags              CreateFlags
 	options            map[string]string
@@ -73,6 +75,7 @@ func (cmd *CmdSiteCreate) NewClient(cobraCommand *cobra.Command, args []string)
 	utils.HandleError(err)
 
 	cmd.Client = cli.GetSkupperClient().SkupperV1alpha1()
+	cmd.KubeClient = cli.GetKubeClient()
 	cmd.Namespace = cli.Namespace
 }
 
@@ -81,7 +84,7 @@ func (cmd *CmdSiteCreate) AddFlags() {
 	cmd.CobraCmd.Flags().StringVar(&cmd.flags.linkAccessType, "link-access-type", "", `configure external access for links from remote sites.
 Choices: [route|loadbalancer]. Default: On OpenShift, route is the default; 
 for other Kubernetes flavors, loadbalancer is the default.`)
-	cmd.CobraCmd.Flags().StringVar(&cmd.flags.serviceAccount, "service-account", "skupper-controller", "the Kubernetes service account under which to run the Skupper controller")
+	cmd.CobraCmd.Flags().StringVar(&cmd.flags.serviceAccount, "service-account", "", "the Kubernetes service account under which to run the Skupper controller")
 	cmd.CobraCmd.Flags().StringVarP(&cmd.flags.output, "output", "o", "", "print resources to the console instead of submitting them to the Skupper controller. Choices: json, yaml")
 }
 
@@ -123,8 +126,8 @@ func (cmd *CmdSiteCreate) ValidateInput(args []string) []error {
 	}
 
 	if cmd.flags.serviceAccount != "" {
-		ok, err := resourceStringValidator.Evaluate(cmd.flags.serviceAccount)
-		if !ok {
+		svcAccount, err := cmd.KubeClient.CoreV1().ServiceAccounts(cmd.Namespace).Get(context.TODO(), cmd.flags.serviceAccount, metav1.GetOptions{})
+		if err != nil || svcAccount == nil {
 			validationErrors = append(validationErrors, fmt.Errorf("service account name is not valid: %s", err))
 		}
 	}
diff --git a/internal/cmd/skupper/site/kube/site_update.go b/internal/cmd/skupper/site/kube/site_update.go
index 7d8415d4..f1ef7a08 100644
--- a/internal/cmd/skupper/site/kube/site_update.go
+++ b/internal/cmd/skupper/site/kube/site_update.go
@@ -3,6 +3,7 @@ package kube
 import (
 	"context"
 	"fmt"
+	"k8s.io/client-go/kubernetes"
 
 	"github.com/skupperproject/skupper/internal/cmd/skupper/utils"
 	"github.com/skupperproject/skupper/internal/kube/client"
@@ -27,6 +28,7 @@ type UpdateFlags struct {
 
 type CmdSiteUpdate struct {
 	Client             skupperv1alpha1.SkupperV1alpha1Interface
+	KubeClient         kubernetes.Interface
 	CobraCmd           cobra.Command
 	flags              UpdateFlags
 	options            map[string]string
@@ -68,6 +70,7 @@ func (cmd *CmdSiteUpdate) NewClient(cobraCommand *cobra.Command, args []string)
 	utils.HandleError(err)
 
 	cmd.Client = cli.GetSkupperClient().SkupperV1alpha1()
+	cmd.KubeClient = cli.GetKubeClient()
 	cmd.Namespace = cli.Namespace
 }
 
@@ -76,14 +79,13 @@ func (cmd *CmdSiteUpdate) AddFlags() {
 	cmd.CobraCmd.Flags().StringVar(&cmd.flags.linkAccessType, "link-access-type", "", `configure external access for links from remote sites.
 Choices: [route|loadbalancer]. Default: On OpenShift, route is the default; 
 for other Kubernetes flavors, loadbalancer is the default.`)
-	cmd.CobraCmd.Flags().StringVar(&cmd.flags.serviceAccount, "service-account", "skupper-controller", "the Kubernetes service account under which to run the Skupper controller")
+	cmd.CobraCmd.Flags().StringVar(&cmd.flags.serviceAccount, "service-account", "", "the Kubernetes service account under which to run the Skupper controller")
 	cmd.CobraCmd.Flags().StringVarP(&cmd.flags.output, "output", "o", "", "print resources to the console instead of submitting them to the Skupper controller. Choices: json, yaml")
 }
 
 func (cmd *CmdSiteUpdate) ValidateInput(args []string) []error {
 
 	var validationErrors []error
-	resourceStringValidator := validator.NewResourceStringValidator()
 	linkAccessTypeValidator := validator.NewOptionValidator(utils.LinkAccessTypes)
 	outputTypeValidator := validator.NewOptionValidator(utils.OutputTypes)
 
@@ -128,8 +130,8 @@ func (cmd *CmdSiteUpdate) ValidateInput(args []string) []error {
 	}
 
 	if cmd.flags.serviceAccount != "" {
-		ok, err := resourceStringValidator.Evaluate(cmd.flags.serviceAccount)
-		if !ok {
+		svcAccount, err := cmd.KubeClient.CoreV1().ServiceAccounts(cmd.Namespace).Get(context.TODO(), cmd.flags.serviceAccount, metav1.GetOptions{})
+		if err != nil || svcAccount == nil {
 			validationErrors = append(validationErrors, fmt.Errorf("service account name is not valid: %s", err))
 		}
 	}
diff --git a/internal/non-kube/client/compat/container_mock.go b/internal/non-kube/client/compat/container_mock.go
index f357e0a7..6f1a7868 100644
--- a/internal/non-kube/client/compat/container_mock.go
+++ b/internal/non-kube/client/compat/container_mock.go
@@ -12,12 +12,12 @@ import (
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/strfmt"
 	"github.com/google/uuid"
-	"github.com/skupperproject/skupper/api/types"
 	"github.com/skupperproject/skupper-libpod/v4/client/containers_compat"
 	"github.com/skupperproject/skupper-libpod/v4/client/networks_compat"
 	"github.com/skupperproject/skupper-libpod/v4/client/system_compat"
 	"github.com/skupperproject/skupper-libpod/v4/client/volumes_compat"
 	"github.com/skupperproject/skupper-libpod/v4/models"
+	"github.com/skupperproject/skupper/api/types"
 	"github.com/skupperproject/skupper/pkg/config"
 	"github.com/skupperproject/skupper/pkg/container"
 )
diff --git a/internal/non-kube/client/compat/network.go b/internal/non-kube/client/compat/network.go
index 409aae00..fd7b3066 100644
--- a/internal/non-kube/client/compat/network.go
+++ b/internal/non-kube/client/compat/network.go
@@ -6,9 +6,9 @@ import (
 
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/strfmt"
-	"github.com/skupperproject/skupper/api/types"
 	"github.com/skupperproject/skupper-libpod/v4/client/networks_compat"
 	"github.com/skupperproject/skupper-libpod/v4/models"
+	"github.com/skupperproject/skupper/api/types"
 	"github.com/skupperproject/skupper/pkg/container"
 	"github.com/skupperproject/skupper/pkg/utils"
 )
diff --git a/internal/non-kube/client/compat/volume.go b/internal/non-kube/client/compat/volume.go
index 8549d2cf..1aa1065f 100644
--- a/internal/non-kube/client/compat/volume.go
+++ b/internal/non-kube/client/compat/volume.go
@@ -6,9 +6,9 @@ import (
 
 	"github.com/go-openapi/runtime"
 	"github.com/go-openapi/strfmt"
-	"github.com/skupperproject/skupper/api/types"
 	"github.com/skupperproject/skupper-libpod/v4/client/volumes_compat"
 	"github.com/skupperproject/skupper-libpod/v4/models"
+	"github.com/skupperproject/skupper/api/types"
 	"github.com/skupperproject/skupper/pkg/container"
 )
 
diff --git a/pkg/apis/skupper/v1alpha1/types.go b/pkg/apis/skupper/v1alpha1/types.go
index 99a474ea..67a1869f 100644
--- a/pkg/apis/skupper/v1alpha1/types.go
+++ b/pkg/apis/skupper/v1alpha1/types.go
@@ -147,7 +147,6 @@ type Listener struct {
 	Status        Status       `json:"status,omitempty"`
 }
 
-
 func (l *Listener) Protocol() corev1.Protocol {
 	if l.Spec.Type == "udp" {
 		return corev1.ProtocolUDP
@@ -266,9 +265,9 @@ type AccessTokenList struct {
 }
 
 type AccessTokenSpec struct {
-	Url    string `json:"url"`
-	Code   string `json:"code"`
-	Ca     string `json:"ca"`
+	Url  string `json:"url"`
+	Code string `json:"code"`
+	Ca   string `json:"ca"`
 }
 
 type AccessTokenStatus struct {
@@ -306,7 +305,7 @@ type AccessGrantStatus struct {
 	Url        string `json:"url"`
 	Code       string `json:"code"`
 	Ca         string `json:"ca"`
-	Redeemed  int    `json:"redeemed,omitempty"`
+	Redeemed   int    `json:"redeemed,omitempty"`
 	Expiration string `json:"expiration,omitempty"`
 	Status     string `json:"status,omitempty"`
 }
diff --git a/pkg/kube/site/ports.go b/pkg/kube/site/ports.go
index ed0248de..e05e59b9 100644
--- a/pkg/kube/site/ports.go
+++ b/pkg/kube/site/ports.go
@@ -63,7 +63,6 @@ func (p ExposedPorts) Unexpose(host string, portname string) *ExposedPortSet {
 	return nil
 }
 
-
 func toServicePorts(desired map[string]Port) map[string]corev1.ServicePort {
 	results := map[string]corev1.ServicePort{}
 	for name, details := range desired {
diff --git a/pkg/site/bindings.go b/pkg/site/bindings.go
index b7f1b9e5..24a72b11 100644
--- a/pkg/site/bindings.go
+++ b/pkg/site/bindings.go
@@ -7,8 +7,8 @@ import (
 	"github.com/skupperproject/skupper/pkg/qdr"
 )
 
-type ListenerConfiguration func (siteId string, listener *skupperv1alpha1.Listener, config *qdr.BridgeConfig)
-type ConnectorConfiguration func (siteId string, connector *skupperv1alpha1.Connector, config *qdr.BridgeConfig)
+type ListenerConfiguration func(siteId string, listener *skupperv1alpha1.Listener, config *qdr.BridgeConfig)
+type ConnectorConfiguration func(siteId string, connector *skupperv1alpha1.Connector, config *qdr.BridgeConfig)
 
 type BindingEventHandler interface {
 	ListenerUpdated(listener *skupperv1alpha1.Listener)
@@ -22,7 +22,7 @@ type Bindings struct {
 	connectors map[string]*skupperv1alpha1.Connector
 	listeners  map[string]*skupperv1alpha1.Listener
 	handler    BindingEventHandler
-	configure  struct{
+	configure  struct {
 		listener  ListenerConfiguration
 		connector ConnectorConfiguration
 	}


Test patch:
diff --git a/internal/cmd/skupper/site/kube/site_create_test.go b/internal/cmd/skupper/site/kube/site_create_test.go
index 9c86a07a..5322785b 100644
--- a/internal/cmd/skupper/site/kube/site_create_test.go
+++ b/internal/cmd/skupper/site/kube/site_create_test.go
@@ -39,7 +39,7 @@ func TestCmdSiteCreate_AddFlags(t *testing.T) {
 	expectedFlagsWithDefaultValue := map[string]interface{}{
 		"enable-link-access": "false",
 		"link-access-type":   "",
-		"service-account":    "skupper-controller",
+		"service-account":    "",
 		"output":             "",
 	}
 	var flagList []string
@@ -117,7 +117,7 @@ func TestCmdSiteCreate_ValidateInput(t *testing.T) {
 			name:           "service account name is not valid.",
 			args:           []string{"my-site"},
 			flags:          &CreateFlags{serviceAccount: "not valid service account name"},
-			expectedErrors: []string{"service account name is not valid: value does not match this regular expression: ^[a-z0-9]([-a-z0-9]*[a-z0-9])*(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])*)*$"},
+			expectedErrors: []string{"service account name is not valid: serviceaccounts \"not valid service account name\" not found"},
 		},
 		{
 			name:  "link access type is not valid",
@@ -147,6 +147,8 @@ func TestCmdSiteCreate_ValidateInput(t *testing.T) {
 			fakeSkupperClient, err := fakeclient.NewFakeClient(command.Namespace, test.k8sObjects, test.skupperObjects, "")
 			assert.Assert(t, err)
 			command.Client = fakeSkupperClient.GetSkupperClient().SkupperV1alpha1()
+			command.KubeClient = fakeSkupperClient.GetKubeClient()
+
 			if test.flags != nil {
 				command.flags = *test.flags
 			}
@@ -437,13 +439,14 @@ func TestCmdSiteCreate_WaitUntilReady(t *testing.T) {
 
 func newCmdSiteCreateWithMocks(namespace string) (*CmdSiteCreate, error) {
 
-	vanclient, err := fakeclient.NewFakeClient(namespace, nil, nil, "")
+	client, err := fakeclient.NewFakeClient(namespace, nil, nil, "")
 	if err != nil {
 		return nil, err
 	}
 	cmdSiteCreate := &CmdSiteCreate{
-		Client:    vanclient.GetSkupperClient().SkupperV1alpha1(),
-		Namespace: namespace,
+		Client:     client.GetSkupperClient().SkupperV1alpha1(),
+		KubeClient: client.GetKubeClient(),
+		Namespace:  namespace,
 	}
 
 	return cmdSiteCreate, nil
diff --git a/internal/cmd/skupper/site/kube/site_update_test.go b/internal/cmd/skupper/site/kube/site_update_test.go
index 2a894fe7..80210de1 100644
--- a/internal/cmd/skupper/site/kube/site_update_test.go
+++ b/internal/cmd/skupper/site/kube/site_update_test.go
@@ -36,7 +36,7 @@ func TestCmdSiteUpdate_AddFlags(t *testing.T) {
 	expectedFlagsWithDefaultValue := map[string]interface{}{
 		"enable-link-access": "false",
 		"link-access-type":   "",
-		"service-account":    "skupper-controller",
+		"service-account":    "",
 		"output":             "",
 	}
 	var flagList []string
@@ -165,7 +165,7 @@ func TestCmdSiteUpdate_ValidateInput(t *testing.T) {
 				},
 			},
 			skupperError:   "",
-			expectedErrors: []string{"service account name is not valid: value does not match this regular expression: ^[a-z0-9]([-a-z0-9]*[a-z0-9])*(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])*)*$"},
+			expectedErrors: []string{"service account name is not valid: serviceaccounts \"not valid service account name\" not found"},
 		},
 		{
 			name:       "link access type is not valid",
@@ -355,6 +355,7 @@ func TestCmdSiteUpdate_ValidateInput(t *testing.T) {
 			fakeSkupperClient, err := fakeclient.NewFakeClient(command.Namespace, test.k8sObjects, test.skupperObjects, test.skupperError)
 			assert.Assert(t, err)
 			command.Client = fakeSkupperClient.GetSkupperClient().SkupperV1alpha1()
+			command.KubeClient = fakeSkupperClient.GetKubeClient()
 
 			if test.flags != nil {
 				command.flags = *test.flags
diff --git a/internal/non-kube/client/compat/container_test.go b/internal/non-kube/client/compat/container_test.go
index 6631ab13..9fba557b 100644
--- a/internal/non-kube/client/compat/container_test.go
+++ b/internal/non-kube/client/compat/container_test.go
@@ -13,8 +13,8 @@ import (
 	"time"
 
 	"github.com/go-openapi/runtime"
-	"github.com/skupperproject/skupper/api/types"
 	"github.com/skupperproject/skupper-libpod/v4/client/containers_compat"
+	"github.com/skupperproject/skupper/api/types"
 	"github.com/skupperproject/skupper/pkg/container"
 	"github.com/skupperproject/skupper/pkg/images"
 	"github.com/skupperproject/skupper/pkg/utils"