diff --git a/charts/spiderpool/README.md b/charts/spiderpool/README.md index 0d18b25f4e..b208e8af61 100644 --- a/charts/spiderpool/README.md +++ b/charts/spiderpool/README.md @@ -371,31 +371,20 @@ helm install spiderpool spiderpool/spiderpool --wait --namespace kube-system \ ### spiderpoolInit parameters -| Name | Description | Value | -| ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | -| `spiderpoolInit.name` | the init job for installing default spiderippool | `spiderpool-init` | -| `spiderpoolInit.binName` | the binName name of spiderpoolInit | `/usr/bin/spiderpool-init` | -| `spiderpoolInit.hostnetwork` | enable hostnetwork mode of spiderpoolInit pod. Notice, if no CNI available before spiderpool installation, must enable this | `true` | -| `spiderpoolInit.image.registry` | the image registry of spiderpoolInit | `ghcr.io` | -| `spiderpoolInit.image.repository` | the image repository of spiderpoolInit | `spidernet-io/spiderpool/spiderpool-controller` | -| `spiderpoolInit.image.pullPolicy` | the image pullPolicy of spiderpoolInit | `IfNotPresent` | -| `spiderpoolInit.image.digest` | the image digest of spiderpoolInit, which takes preference over tag | `""` | -| `spiderpoolInit.image.tag` | the image tag of spiderpoolInit, overrides the image tag whose default is the chart appVersion. | `""` | -| `spiderpoolInit.image.imagePullSecrets` | the image imagePullSecrets of spiderpoolInit | `[]` | -| `spiderpoolInit.priorityClassName` | the priority Class Name for spiderpoolInit | `system-node-critical` | -| `spiderpoolInit.affinity` | the affinity of spiderpoolInit | `{}` | -| `spiderpoolInit.extraArgs` | the additional arguments of spiderpoolInit container | `[]` | -| `spiderpoolInit.resources.limits.cpu` | the cpu limit of spiderpoolInit pod | `200m` | -| `spiderpoolInit.resources.limits.memory` | the memory limit of spiderpoolInit pod | `256Mi` | -| `spiderpoolInit.resources.requests.cpu` | the cpu requests of spiderpoolInit pod | `100m` | -| `spiderpoolInit.resources.requests.memory` | the memory requests of spiderpoolInit pod | `128Mi` | -| `spiderpoolInit.readinessProbe.failureThreshold` | the failure threshold of startup probe for spiderpool-init health checking | `30` | -| `spiderpoolInit.readinessProbe.periodSeconds` | the period seconds of startup probe for spiderpool-init health checking | `10` | -| `spiderpoolInit.extraEnv` | the additional environment variables of spiderpoolInit container | `[]` | -| `spiderpoolInit.securityContext` | the security Context of spiderpoolInit pod | `{}` | -| `spiderpoolInit.podAnnotations` | the additional annotations of spiderpoolInit pod | `{}` | -| `spiderpoolInit.podLabels` | the additional label of spiderpoolInit pod | `{}` | -| `spiderpoolInit.serviceAccount.annotations` | the annotations of spiderpoolInit service account | `{}` | +| Name | Description | Value | +| ------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------- | +| `spiderpoolInit.name` | the init job for installing default spiderippool | `spiderpool-init` | +| `spiderpoolInit.binName` | the binName name of spiderpoolInit | `/usr/bin/spiderpool-init` | +| `spiderpoolInit.image.registry` | the image registry of spiderpoolInit | `ghcr.io` | +| `spiderpoolInit.image.repository` | the image repository of spiderpoolInit | `spidernet-io/spiderpool/spiderpool-controller` | +| `spiderpoolInit.image.pullPolicy` | the image pullPolicy of spiderpoolInit | `IfNotPresent` | +| `spiderpoolInit.image.digest` | the image digest of spiderpoolInit, which takes preference over tag | `""` | +| `spiderpoolInit.image.tag` | the image tag of spiderpoolInit, overrides the image tag whose default is the chart appVersion. | `""` | +| `spiderpoolInit.image.imagePullSecrets` | the image imagePullSecrets of spiderpoolInit | `[]` | +| `spiderpoolInit.extraArgs` | the additional arguments of spiderpoolInit container | `[]` | +| `spiderpoolInit.extraEnv` | the additional environment variables of spiderpoolInit container | `[]` | +| `spiderpoolInit.securityContext` | the security Context of spiderpoolInit pod | `{}` | +| `spiderpoolInit.serviceAccount.annotations` | the annotations of spiderpoolInit service account | `{}` | ### sriov network operator parameters diff --git a/charts/spiderpool/templates/pod.yaml b/charts/spiderpool/templates/pod.yaml index 01aced2bab..05f08a7058 100644 --- a/charts/spiderpool/templates/pod.yaml +++ b/charts/spiderpool/templates/pod.yaml @@ -1,159 +1,104 @@ -{{- if or .Values.ipam.enableIPv4 .Values.ipam.enableIPv6 -}} -{{- if or .Values.clusterDefaultPool.installIPv4IPPool .Values.clusterDefaultPool.installIPv6IPPool .Values.coordinator.enabled -}} -apiVersion: v1 -kind: Pod +apiVersion: batch/v1 +kind: Job metadata: name: {{ .Values.spiderpoolInit.name | trunc 63 | trimSuffix "-" }} namespace: {{ .Release.Namespace | quote }} - labels: - {{- include "spiderpool.spiderpoolInit.selectorLabels" . | nindent 4 }} - {{- if .Values.global.commonLabels }} - {{- include "tplvalues.render" ( dict "value" .Values.global.commonLabels "context" $ ) | nindent 4 }} - {{- end }} - {{- if .Values.spiderpoolInit.podLabels }} - {{- include "tplvalues.render" ( dict "value" .Values.spiderpoolInit.podLabels "context" $ ) | nindent 4 }} - {{- end }} annotations: - {{- if .Values.global.commonAnnotations }} - {{- include "tplvalues.render" ( dict "value" .Values.global.commonAnnotations "context" $ ) | nindent 4 }} - {{- end }} - {{- if .Values.spiderpoolInit.podAnnotations }} - {{- include "tplvalues.render" ( dict "value" .Values.spiderpoolInit.podAnnotations "context" $ ) | nindent 4 }} - {{- end }} + "helm.sh/hook": post-install spec: - {{- if .Values.spiderpoolInit.image.imagePullSecrets }} - imagePullSecrets: - {{- with .Values.spiderpoolInit.image.imagePullSecrets }} - {{- toYaml . | trim | nindent 2 }} - {{- end }} - {{- end }} - serviceAccountName: {{ .Values.spiderpoolInit.name | trunc 63 | trimSuffix "-" }} - priorityClassName: {{ default "system-node-critical" .Values.spiderpoolInit.priorityClassName }} - {{- if .Values.spiderpoolInit.hostnetwork }} - hostNetwork: true - dnsPolicy: ClusterFirstWithHostNet - {{- else }} - hostNetwork: false - dnsPolicy: ClusterFirst - {{- end }} - restartPolicy: Never - {{- with .Values.spiderpoolInit.tolerations }} - tolerations: - {{- toYaml . | nindent 2 }} - {{- end }} - {{- with .Values.spiderpoolInit.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 4 }} - {{- end }} - {{- if .Values.spiderpoolInit.affinity }} - affinity: - {{- include "tplvalues.render" (dict "value" .Values.spiderpoolInit.affinity "context" $) | nindent 2 }} - {{- end }} - containers: - - name: {{ .Values.spiderpoolInit.name | trunc 63 | trimSuffix "-" }} - image: {{ include "spiderpool.spiderpoolInit.image" . | quote }} - imagePullPolicy: {{ .Values.spiderpoolInit.image.pullPolicy }} - command: - - {{ .Values.spiderpoolInit.binName }} - {{- with .Values.spiderpoolInit.extraArgs }} - args: - {{- toYaml . | trim | nindent 4 }} - {{- end }} - readinessProbe: - exec: + template: + spec: + serviceAccountName: {{ .Values.spiderpoolInit.name | trunc 63 | trimSuffix "-" }} + hostNetwork: true + restartPolicy: Never + containers: + - name: {{ .Values.spiderpoolInit.name | trunc 63 | trimSuffix "-" }} + image: {{ include "spiderpool.spiderpoolInit.image" . | quote }} + imagePullPolicy: {{ .Values.spiderpoolInit.image.pullPolicy }} command: - - cat - - "/etc/spiderpool/ready" - initialDelaySeconds: 15 - periodSeconds: {{ .Values.spiderpoolInit.readinessProbe.periodSeconds }} - successThreshold: 1 - failureThreshold: {{ .Values.spiderpoolInit.readinessProbe.failureThreshold }} - timeoutSeconds: 1 - {{- with .Values.spiderpoolInit.resources }} - resources: - {{- toYaml . | trim | nindent 6 }} - {{- end }} - {{- with .Values.spiderpoolInit.securityContext }} - securityContext: - {{- toYaml . | nindent 4 }} - {{- end }} - env: - {{- with .Values.spiderpoolInit.extraEnv }} - {{- toYaml . | nindent 4 }} - {{- end }} - - name: SPIDERPOOL_NAMESPACE - value: {{ .Release.Namespace | quote }} - - name: SPIDERPOOL_CONTROLLER_NAME - value: {{ .Values.spiderpoolController.name | trunc 63 | trimSuffix "-" }} - - name: SPIDERPOOL_AGENT_NAME - value: {{ .Values.spiderpoolAgent.name | trunc 63 | trimSuffix "-" | quote }} - {{- if .Values.coordinator.enabled }} - - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_NAME - value: {{ .Values.coordinator.name | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_MODE - value: {{ .Values.coordinator.mode | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_POD_CIDR_TYPE - value: {{ .Values.coordinator.podCIDRType | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_DETECT_GATEWAY - value: {{ .Values.coordinator.detectGateway | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_DETECT_IP_CONFLICT - value: {{ .Values.coordinator.detectIPConflict | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_TUNE_POD_ROUTES - value: {{ .Values.coordinator.tunePodRoutes | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_HIJACK_CIDR - value: {{ toJson .Values.coordinator.hijackCIDR | quote }} - {{- end }} - {{- if and .Values.clusterDefaultPool.installIPv4IPPool .Values.ipam.enableIPv4 }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV4_IPPOOL_NAME - value: {{ .Values.clusterDefaultPool.ipv4IPPoolName | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV4_IPPOOL_SUBNET - value: {{ .Values.clusterDefaultPool.ipv4Subnet | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV4_IPPOOL_IPRANGES - value: {{ toJson .Values.clusterDefaultPool.ipv4IPRanges | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV4_IPPOOL_GATEWAY - value: {{ .Values.clusterDefaultPool.ipv4Gateway | quote }} - {{- if .Values.ipam.enableSpiderSubnet }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV4_SUBNET_NAME - value: {{ .Values.clusterDefaultPool.ipv4SubnetName | quote }} - {{- end }} - {{- end }} - {{- if and .Values.clusterDefaultPool.installIPv6IPPool .Values.ipam.enableIPv6 }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_NAME - value: {{ .Values.clusterDefaultPool.ipv6IPPoolName | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_SUBNET - value: {{ .Values.clusterDefaultPool.ipv6Subnet | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_IPRANGES - value: {{ toJson .Values.clusterDefaultPool.ipv6IPRanges | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_GATEWAY - value: {{ .Values.clusterDefaultPool.ipv6Gateway | quote }} - {{- if .Values.ipam.enableSpiderSubnet }} - - name: SPIDERPOOL_INIT_DEFAULT_IPV6_SUBNET_NAME - value: {{ .Values.clusterDefaultPool.ipv6SubnetName | quote }} - {{- end }} - {{- end }} - - name: SPIDERPOOL_INIT_ENABLE_MULTUS_CONFIG - value: {{ .Values.multus.enableMultusConfig | quote }} - - name: SPIDERPOOL_INIT_INSTALL_MULTUS - value: {{ .Values.multus.multusCNI.install | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_CNI_NAME - value: {{ .Values.multus.multusCNI.defaultCniCRName | quote }} - - name: SPIDERPOOL_INIT_DEFAULT_CNI_NAMESPACE - value: {{ .Release.Namespace | quote }} - - name: SPIDERPOOL_INIT_MULTUS_CONFIGMAP - value: {{ .Values.multus.multusCNI.name | trunc 63 | trimSuffix "-" | quote }} - {{- if eq .Values.multus.multusCNI.defaultCniCRName "" }} - - name: SPIDERPOOL_INIT_DEFAULT_CNI_DIR - value: {{ .Values.global.cniConfHostPath | quote }} - - name: SPIDERPOOL_INIT_READINESS_FILE - value: "/etc/spiderpool/ready" - volumeMounts: - - name: cni - mountPath: {{ .Values.global.cniConfHostPath }} - volumes: - - name: cni - hostPath: - path: {{ .Values.global.cniConfHostPath }} - {{- end }} + - {{ .Values.spiderpoolInit.binName }} + {{- with .Values.spiderpoolInit.extraArgs }} + args: + {{- toYaml . | trim | nindent 4 }} + {{- end }} + {{- with .Values.spiderpoolInit.securityContext }} + securityContext: + {{- toYaml . | nindent 4 }} + {{- end }} + env: + - name: SPIDERPOOL_NAMESPACE + value: {{ .Release.Namespace | quote }} + - name: SPIDERPOOL_CONTROLLER_NAME + value: {{ .Values.spiderpoolController.name | trunc 63 | trimSuffix "-" }} + - name: SPIDERPOOL_AGENT_NAME + value: {{ .Values.spiderpoolAgent.name | trunc 63 | trimSuffix "-" | quote }} + {{- if .Values.coordinator.enabled }} + - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_NAME + value: {{ .Values.coordinator.name | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_MODE + value: {{ .Values.coordinator.mode | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_POD_CIDR_TYPE + value: {{ .Values.coordinator.podCIDRType | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_DETECT_GATEWAY + value: {{ .Values.coordinator.detectGateway | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_DETECT_IP_CONFLICT + value: {{ .Values.coordinator.detectIPConflict | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_TUNE_POD_ROUTES + value: {{ .Values.coordinator.tunePodRoutes | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_COORDINATOR_HIJACK_CIDR + value: {{ toJson .Values.coordinator.hijackCIDR | quote }} + {{- end }} + {{- if and .Values.clusterDefaultPool.installIPv4IPPool .Values.ipam.enableIPv4 }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV4_IPPOOL_NAME + value: {{ .Values.clusterDefaultPool.ipv4IPPoolName | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV4_IPPOOL_SUBNET + value: {{ .Values.clusterDefaultPool.ipv4Subnet | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV4_IPPOOL_IPRANGES + value: {{ toJson .Values.clusterDefaultPool.ipv4IPRanges | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV4_IPPOOL_GATEWAY + value: {{ .Values.clusterDefaultPool.ipv4Gateway | quote }} + {{- if .Values.ipam.spidersubnet.enable }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV4_SUBNET_NAME + value: {{ .Values.clusterDefaultPool.ipv4SubnetName | quote }} + {{- end }} + {{- end }} + {{- if and .Values.clusterDefaultPool.installIPv6IPPool .Values.ipam.enableIPv6 }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_NAME + value: {{ .Values.clusterDefaultPool.ipv6IPPoolName | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_SUBNET + value: {{ .Values.clusterDefaultPool.ipv6Subnet | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_IPRANGES + value: {{ toJson .Values.clusterDefaultPool.ipv6IPRanges | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_GATEWAY + value: {{ .Values.clusterDefaultPool.ipv6Gateway | quote }} + {{- if .Values.ipam.spidersubnet.enable }} + - name: SPIDERPOOL_INIT_DEFAULT_IPV6_SUBNET_NAME + value: {{ .Values.clusterDefaultPool.ipv6SubnetName | quote }} + {{- end }} + {{- end }} + - name: SPIDERPOOL_INIT_ENABLE_MULTUS_CONFIG + value: {{ .Values.multus.enableMultusConfig | quote }} + - name: SPIDERPOOL_INIT_INSTALL_MULTUS + value: {{ .Values.multus.multusCNI.install | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_CNI_NAME + value: {{ .Values.multus.multusCNI.defaultCniCRName | quote }} + - name: SPIDERPOOL_INIT_DEFAULT_CNI_NAMESPACE + value: {{ .Release.Namespace | quote }} + - name: SPIDERPOOL_INIT_MULTUS_CONFIGMAP + value: {{ .Values.multus.multusCNI.name | trunc 63 | trimSuffix "-" | quote }} + {{- if eq .Values.multus.multusCNI.defaultCniCRName "" }} + - name: SPIDERPOOL_INIT_DEFAULT_CNI_DIR + value: {{ .Values.global.cniConfHostPath | quote }} + - name: SPIDERPOOL_INIT_READINESS_FILE + value: "/etc/spiderpool/ready" + volumeMounts: + - name: cni + mountPath: {{ .Values.global.cniConfHostPath }} + volumes: + - name: cni + hostPath: + path: {{ .Values.global.cniConfHostPath }} + {{- end }} --- apiVersion: v1 kind: ServiceAccount @@ -174,5 +119,4 @@ metadata: {{- include "tplvalues.render" ( dict "value" .Values.spiderpoolInit.serviceAccount.annotations "context" $ ) | nindent 4 }} {{- end }} {{- end }} -{{- end -}} -{{- end -}} \ No newline at end of file + \ No newline at end of file diff --git a/charts/spiderpool/values.yaml b/charts/spiderpool/values.yaml index 4ba75a49ee..f9cdde2dd4 100644 --- a/charts/spiderpool/values.yaml +++ b/charts/spiderpool/values.yaml @@ -758,9 +758,6 @@ spiderpoolInit: ## @param spiderpoolInit.binName the binName name of spiderpoolInit binName: "/usr/bin/spiderpool-init" - ## @param spiderpoolInit.hostnetwork enable hostnetwork mode of spiderpoolInit pod. Notice, if no CNI available before spiderpool installation, must enable this - hostnetwork: true - image: ## @param spiderpoolInit.image.registry the image registry of spiderpoolInit registry: ghcr.io @@ -781,42 +778,9 @@ spiderpoolInit: imagePullSecrets: [] # - name: "image-pull-secret" - ## @param spiderpoolInit.priorityClassName the priority Class Name for spiderpoolInit - priorityClassName: "system-node-critical" - - ## @skip spiderpoolInit.tolerations - tolerations: - - operator: Exists - - ## @skip spiderpoolInit.nodeSelector.kubernetes.io/os - nodeSelector: - kubernetes.io/os: linux - - ## @param spiderpoolInit.affinity the affinity of spiderpoolInit - affinity: {} - ## @param spiderpoolInit.extraArgs the additional arguments of spiderpoolInit container extraArgs: [] - resources: - limits: - ## @param spiderpoolInit.resources.limits.cpu the cpu limit of spiderpoolInit pod - cpu: 200m - ## @param spiderpoolInit.resources.limits.memory the memory limit of spiderpoolInit pod - memory: 256Mi - requests: - ## @param spiderpoolInit.resources.requests.cpu the cpu requests of spiderpoolInit pod - cpu: 100m - ## @param spiderpoolInit.resources.requests.memory the memory requests of spiderpoolInit pod - memory: 128Mi - - readinessProbe: - ## @param spiderpoolInit.readinessProbe.failureThreshold the failure threshold of startup probe for spiderpool-init health checking - failureThreshold: 30 - - ## @param spiderpoolInit.readinessProbe.periodSeconds the period seconds of startup probe for spiderpool-init health checking - periodSeconds: 10 - ## @param spiderpoolInit.extraEnv the additional environment variables of spiderpoolInit container extraEnv: [] @@ -824,12 +788,6 @@ spiderpoolInit: securityContext: {} # runAsUser: 0 - ## @param spiderpoolInit.podAnnotations the additional annotations of spiderpoolInit pod - podAnnotations: {} - - ## @param spiderpoolInit.podLabels the additional label of spiderpoolInit pod - podLabels: {} - serviceAccount: ## @param spiderpoolInit.serviceAccount.annotations the annotations of spiderpoolInit service account annotations: {} diff --git a/cmd/spiderpool-init/cmd/client.go b/cmd/spiderpool-init/cmd/client.go index c1198f2d1d..f8ef23d3f3 100644 --- a/cmd/spiderpool-init/cmd/client.go +++ b/cmd/spiderpool-init/cmd/client.go @@ -60,14 +60,9 @@ func (c *CoreClient) WaitForCoordinatorCreated(ctx context.Context, coord *spide return nil } - select { - case <-ctx.Done(): - return ctx.Err() - default: - interval := retryIntervalSec * time.Second - logger.Sugar().Infof("Failed to create default Coordinator %s, recreate in %s: %v", coord.Name, interval, err) - time.Sleep(interval) - } + interval := retryIntervalSec * time.Second + logger.Sugar().Infof("Failed to create default Coordinator %s, recreate in %s: %v", coord.Name, interval, err) + time.Sleep(interval) } } @@ -86,14 +81,9 @@ func (c *CoreClient) WaitForSubnetCreated(ctx context.Context, subnet *spiderpoo return nil } - select { - case <-ctx.Done(): - return ctx.Err() - default: - interval := retryIntervalSec * time.Second - logger.Sugar().Infof("Failed to create default IPv%d Subnet %s, recreate in %s: %v", *subnet.Spec.IPVersion, subnet.Name, interval, err) - time.Sleep(interval) - } + interval := retryIntervalSec * time.Second + logger.Sugar().Infof("Failed to create default IPv%d Subnet %s, recreate in %s: %v", *subnet.Spec.IPVersion, subnet.Name, interval, err) + time.Sleep(interval) } } @@ -131,14 +121,9 @@ func (c *CoreClient) WaitForEndpointReady(ctx context.Context, namespace, name s return nil } - select { - case <-ctx.Done(): - return ctx.Err() - default: - interval := retryIntervalSec * time.Second - logger.Sugar().Infof("Spiderpool controller is not ready, recheck in %s", interval) - time.Sleep(interval) - } + interval := retryIntervalSec * time.Second + logger.Sugar().Infof("Spiderpool controller is not ready, recheck in %s", interval) + time.Sleep(interval) } } @@ -170,52 +155,41 @@ func (c *CoreClient) WaitMultusCNIConfigCreated(ctx context.Context, multuscnico return nil } - select { - case <-ctx.Done(): - return ctx.Err() - default: - interval := retryIntervalSec * time.Second - logger.Sugar().Infof("Failed to create multuscniconfig %s/%s, recreate in %s: %v", multuscniconfig.Namespace, multuscniconfig.Name, interval, err) - time.Sleep(interval) - } + interval := retryIntervalSec * time.Second + logger.Sugar().Infof("Failed to create multuscniconfig %s/%s, recreate in %s: %v", multuscniconfig.Namespace, multuscniconfig.Name, interval, err) + time.Sleep(interval) } } func (c *CoreClient) WaitPodListReady(ctx context.Context, namespace string, labels map[string]string) error { logger := logutils.FromContext(ctx) + ticker := time.NewTicker(retryIntervalSec * time.Second) + defer ticker.Stop() var podList corev1.PodList - var err error - noReady := true - interval := retryIntervalSec * time.Second - for noReady { - if err = c.List(ctx, &podList, client.MatchingLabels(labels), client.InNamespace(namespace)); err != nil { + for { + <-ticker.C + if err := c.List(ctx, &podList, client.MatchingLabels(labels), client.InNamespace(namespace)); err != nil { logger.Sugar().Errorf("failed to get spiderAgent pods: %v, retrying...", err) - time.Sleep(interval) continue } if podList.Items == nil { - time.Sleep(interval) continue } - noReady = false + ready := true for _, pod := range podList.Items { if pod.Status.Phase != corev1.PodRunning { - noReady = true + ready = false break } } - select { - case <-ctx.Done(): - return ctx.Err() - default: - logger.Sugar().Info("spiderpool-agent not ready, waiting...") - time.Sleep(interval) + if ready { + logger.Sugar().Infof("spiderpool-agent is ready") + return nil } + logger.Sugar().Infof("spiderpool-agent is not ready, phase: %v, retrying in %vs", podList.Items[0].Status.Phase, retryIntervalSec) } - - return nil } diff --git a/cmd/spiderpool-init/cmd/root.go b/cmd/spiderpool-init/cmd/root.go index 83fb319e74..49ff174ddd 100644 --- a/cmd/spiderpool-init/cmd/root.go +++ b/cmd/spiderpool-init/cmd/root.go @@ -5,7 +5,6 @@ package cmd import ( "context" - "time" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,7 +26,7 @@ func Execute() { logger.Fatal(err.Error()) } - ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second) + ctx, cancel := context.WithCancel(context.Background()) defer cancel() if err := client.WaitForEndpointReady(ctx, config.Namespace, config.ControllerName); err != nil { @@ -157,7 +156,5 @@ func Execute() { logger.Fatal(err.Error()) } - // helm wait - time.Sleep(300 * time.Second) logger.Info("Finish init") } diff --git a/test/scripts/debugEnv.sh b/test/scripts/debugEnv.sh index 6f79222068..bfad1b1638 100755 --- a/test/scripts/debugEnv.sh +++ b/test/scripts/debugEnv.sh @@ -101,9 +101,8 @@ elif [ "$TYPE"x == "detail"x ] ; then echo "" echo "=============== spiderpool-init describe ============== " - POD="spiderpool-init" - echo "---------kubectl describe pod ${POD} -n ${NAMESPACE} " - kubectl describe pod ${POD} -n ${NAMESPACE} --kubeconfig ${E2E_KUBECONFIG} + echo "---------kubectl describe pod -l job-name=spiderpool-init -n ${NAMESPACE} " + kubectl describe pod -l job-name=spiderpool-init -n ${NAMESPACE} --kubeconfig ${E2E_KUBECONFIG} echo "" echo "=============== spiderpool-controller logs ============== " @@ -128,8 +127,8 @@ elif [ "$TYPE"x == "detail"x ] ; then echo "" echo "=============== spiderpool-init logs ============== " POD="spiderpool-init" - echo "--------- kubectl logs ${POD} -n ${NAMESPACE} " - kubectl logs ${POD} -n ${NAMESPACE} --kubeconfig ${E2E_KUBECONFIG} + echo "--------- kubectl logs -l job-name=spiderpool-init -n ${NAMESPACE} " + kubectl logs -l job-name=spiderpool-init -n ${NAMESPACE} --kubeconfig ${E2E_KUBECONFIG} echo "" echo "=============== spiderpool crd spiderippool ============== " diff --git a/test/scripts/install-multus.sh b/test/scripts/install-multus.sh index 46d41ed1dc..a763797268 100755 --- a/test/scripts/install-multus.sh +++ b/test/scripts/install-multus.sh @@ -377,7 +377,7 @@ EOF kubectl wait --for=condition=ready -l app.kubernetes.io/component=spiderpool-agent --timeout=100s pod -n kube-system --kubeconfig ${E2E_KUBECONFIG} || \ ( kubectl get pod -n kube-system --kubeconfig ${E2E_KUBECONFIG} ; \ - kubectl logs -n kube-system spiderpool-init --kubeconfig ${E2E_KUBECONFIG} ; exit 1 ) + kubectl logs -n kube-system -l job-name=spiderpool-init --kubeconfig ${E2E_KUBECONFIG} ; exit 1 ) Install::MultusCR Install::SpiderpoolCR