From 6b0f55bf73cb4ef8f8c5a2a2d98c90e60d8b26b8 Mon Sep 17 00:00:00 2001 From: baoyinghai_yewu Date: Fri, 1 Nov 2024 14:12:11 +0800 Subject: [PATCH] fix: create api-server-external-service Signed-off-by: baoyinghai_yewu --- cmd/kubenest/node-agent/app/serve/serve.go | 2 +- pkg/kubenest/controlplane/endpoint.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/kubenest/node-agent/app/serve/serve.go b/cmd/kubenest/node-agent/app/serve/serve.go index a4bc5366d..0ecedf783 100644 --- a/cmd/kubenest/node-agent/app/serve/serve.go +++ b/cmd/kubenest/node-agent/app/serve/serve.go @@ -57,7 +57,7 @@ func init() { func serveCmdRun(_ *cobra.Command, _ []string) error { user := viper.GetString("WEB_USER") password := viper.GetString("WEB_PASS") - port := viper.GetString("WEB_PORT") + port := viper.GetString("WEB_PORT") if len(user) == 0 || len(password) == 0 { log.Errorf("-user and -password are required %s %s", user, password) return errors.New("-user and -password are required") diff --git a/pkg/kubenest/controlplane/endpoint.go b/pkg/kubenest/controlplane/endpoint.go index 2a815781a..e809eddd5 100644 --- a/pkg/kubenest/controlplane/endpoint.go +++ b/pkg/kubenest/controlplane/endpoint.go @@ -105,12 +105,14 @@ func CreateOrUpdateAPIServerExternalService(kubeClient kubernetes.Interface) err } _, err = kubeClient.CoreV1().Services(constants.DefaultNs).Get(context.TODO(), constants.APIServerExternalService, metav1.GetOptions{}) if err != nil { - if !apierrors.IsNotFound(err) { + if apierrors.IsNotFound(err) { // Try to create the service _, err = kubeClient.CoreV1().Services(constants.DefaultNs).Create(context.TODO(), &svc, metav1.CreateOptions{}) if err != nil { return fmt.Errorf("error when creating api-server-external-service: %w", err) } + } else { + return fmt.Errorf("error when get api-server-external-service: %w", err) } } klog.V(4).Info("successfully created api-server-external-service service")