diff --git a/hack/k8s-in-k8s/kubelet_node_helper.sh b/hack/k8s-in-k8s/kubelet_node_helper.sh index f128a755b..3f409fd0b 100755 --- a/hack/k8s-in-k8s/kubelet_node_helper.sh +++ b/hack/k8s-in-k8s/kubelet_node_helper.sh @@ -176,7 +176,11 @@ function revert() { echo "exec(4/5): execute join cmd...." - if [ "$USE_KUBEADM" = "true" ]; then + if [ -z "$USE_KUBEADM" ]; then + # if "USE_KUBEADM is not set, default set to true" + export USE_KUBEADM=true + fi + if [ "$USE_KUBEADM" = true ]; then echo "use kubeadm to join node to host" kubeadm join --config "$PATH_FILE_TMP/kubeadm.cfg.current" if [ $? -ne 0 ]; then @@ -200,13 +204,13 @@ function revert() { exit 1 fi - if [ "$USE_KUBEADM" = "false" ]; then + if [ "$USE_KUBEADM" = false ]; then systemctl start kubelet elapsed_time=0 while [ $elapsed_time -lt $KUBELET_CONF_TIMEOUT ]; do - if [ -f "/etc/kubernetes/kubelet.conf" ]; then - rm -f "/etc/kubernetes/bootstrap-kubelet.conf" + if [ -f "${PATH_KUBERNETES}/${KUBELET_KUBE_CONFIG_NAME}" ]; then + rm -f "${PATH_KUBERNETES}/bootstrap-kubelet.conf" echo "Deleted bootstrap-kubelet.conf file as kubelet.conf exists." break fi @@ -311,7 +315,7 @@ function check() { echo "check(2/2): copy kubeadm-flags.env to create $PATH_FILE_TMP , remove args[cloud-provider] and taints" # Since this function is used both to detach nodes, we need to make sure we haven't copied kubeadm-flags.env before if [ ! -f "${PATH_FILE_TMP}/kubeadm-flags.env.origin" ]; then - cp "$PATH_KUBELET_LIB/kubeadm-flags.env" "${PATH_FILE_TMP}/kubeadm-flags.env.origin" + cp "${PATH_KUBELET_LIB}/kubeadm-flags.env" "${PATH_FILE_TMP}/kubeadm-flags.env.origin" fi sed -e "s| --cloud-provider=external | |g" -e "w ${PATH_FILE_TMP}/kubeadm-flags.env" "$PATH_KUBELET_LIB/kubeadm-flags.env" sed -i "s| --register-with-taints=node.kosmos.io/unschedulable:NoSchedule||g" "${PATH_FILE_TMP}/kubeadm-flags.env" diff --git a/pkg/kubenest/controller/endpoints.sync.controller/apiserver_external_sync_controller.go b/pkg/kubenest/controller/endpoints.sync.controller/apiserver_external_sync_controller.go index 231cb0f29..b67075ae7 100644 --- a/pkg/kubenest/controller/endpoints.sync.controller/apiserver_external_sync_controller.go +++ b/pkg/kubenest/controller/endpoints.sync.controller/apiserver_external_sync_controller.go @@ -57,12 +57,12 @@ func (e *ApiServerExternalSyncController) SyncApiServerExternalEPS(ctx context.C kubeEndpoints, err := k8sClient.CoreV1().Endpoints(constants.DefaultNs).Get(ctx, "kubernetes", metav1.GetOptions{}) if err != nil { klog.Errorf("Error getting endpoints: %v", err) - return fmt.Errorf("failed to get endpoints for kubernetes service: %v", err) + return err } else { - klog.Infof("Endpoints for service 'kubernetes': %v", kubeEndpoints) + klog.V(4).Infof("Endpoints for service 'kubernetes': %v", kubeEndpoints) for _, subset := range kubeEndpoints.Subsets { for _, address := range subset.Addresses { - klog.Infof("IP: %s", address.IP) + klog.V(4).Infof("IP: %s", address.IP) } } } @@ -72,39 +72,42 @@ func (e *ApiServerExternalSyncController) SyncApiServerExternalEPS(ctx context.C } if kubeEndpoints.Subsets[0].Addresses == nil || len(kubeEndpoints.Subsets[0].Addresses) == 0 { - return fmt.Errorf("eps %s Addresses length is nil", "kubernetes") + klog.Errorf("eps %s Addresses length is nil", "kubernetes") + return err } apiServerExternalEndpoints, err := k8sClient.CoreV1().Endpoints(constants.DefaultNs).Get(ctx, constants.ApiServerExternalService, metav1.GetOptions{}) if err != nil && !apierrors.IsNotFound(err) { - return fmt.Errorf("failed to get endpoints for %s : %v", constants.ApiServerExternalService, err) + klog.Errorf("failed to get endpoints for %s : %v", constants.ApiServerExternalService, err) + return err } updateEPS := apiServerExternalEndpoints.DeepCopy() if apiServerExternalEndpoints != nil { - klog.Infof("apiServerExternalEndpoints: %v", apiServerExternalEndpoints) + klog.V(4).Infof("apiServerExternalEndpoints: %v", apiServerExternalEndpoints) } else { - klog.Info("apiServerExternalEndpoints is nil") + klog.V(4).Info("apiServerExternalEndpoints is nil") } if updateEPS != nil { - klog.Infof("updateEPS: %v", updateEPS) + klog.V(4).Infof("updateEPS: %v", updateEPS) } else { - klog.Info("updateEPS is nil") + klog.V(4).Info("updateEPS is nil") } if len(updateEPS.Subsets) == 1 && len(updateEPS.Subsets[0].Addresses) == 1 { ip := kubeEndpoints.Subsets[0].Addresses[0].IP - klog.Infof("IP address: %s", ip) + klog.V(4).Infof("IP address: %s", ip) updateEPS.Subsets[0].Addresses[0].IP = ip if _, err := k8sClient.CoreV1().Endpoints(constants.DefaultNs).Update(ctx, updateEPS, metav1.UpdateOptions{}); err != nil { - return fmt.Errorf("failed to update endpoints for api-server-external-service: %v", err) + klog.Errorf("failed to update endpoints for api-server-external-service: %v", err) + return err } } else { klog.ErrorS(err, "Unexpected format of endpoints for api-server-external-service", "endpoint_data", updateEPS) - return fmt.Errorf("unexpected format of endpoints for api-server-external-service") + return err } return nil @@ -137,7 +140,7 @@ func (e *ApiServerExternalSyncController) Reconcile(ctx context.Context, request return reconcile.Result{}, nil } - if targetVirtualCluster.Status.Phase != v1alpha1.AllNodeReady && targetVirtualCluster.Status.Phase != v1alpha1.Completed { + if targetVirtualCluster.Status.Phase != v1alpha1.Initialized { return reconcile.Result{RequeueAfter: utils.DefaultRequeueTime}, nil } diff --git a/pkg/kubenest/controlplane/endpoint.go b/pkg/kubenest/controlplane/endpoint.go index f0e05a76e..cf67d09ec 100644 --- a/pkg/kubenest/controlplane/endpoint.go +++ b/pkg/kubenest/controlplane/endpoint.go @@ -33,7 +33,7 @@ func EnsureApiServerExternalEndPoint(dynamicClient dynamic.Interface) error { } func installApiServerExternalEndpointInVirtualCluster(dynamicClient dynamic.Interface) error { - klog.Info("begin to get kubernetes endpoint") + klog.V(4).Info("begin to get kubernetes endpoint") kubeEndpointUnstructured, err := dynamicClient.Resource(schema.GroupVersionResource{ Group: "", Version: "v1", @@ -74,7 +74,7 @@ func installApiServerExternalEndpointInVirtualCluster(dynamicClient dynamic.Inte klog.Error("create api-server-external-service endpoint failed", err) return errors.Wrap(err, "failed to create api-server-external-service endpoint") } else { - klog.Info("success create api-server-external-service endpoint:", createResult) + klog.V(4).Info("success create api-server-external-service endpoint:", createResult) } } else { return errors.New("kubernetes endpoint does not exist") @@ -110,7 +110,7 @@ func installApiServerExternalServiceInVirtualCluster(dynamicClient dynamic.Inter } func getEndPointPort(dynamicClient dynamic.Interface) (int32, error) { - klog.Info("begin to get Endpoints ports...") + klog.V(4).Info("begin to get Endpoints ports...") endpointsRes := dynamicClient.Resource(schema.GroupVersionResource{ Group: "", Version: "v1", @@ -153,6 +153,6 @@ func getEndPointPort(dynamicClient dynamic.Interface) (int32, error) { return 0, fmt.Errorf("port field not found or error parsing it") } - klog.Infof("The port number was successfully obtained: %d", portNum) + klog.V(4).Infof("The port number was successfully obtained: %d", portNum) return int32(portNum), nil }