update operator default timeout

Signed-off-by: Vacant2333 <rentian.zhou@daocloud.io>
This commit is contained in:
Vacant2333 2023-08-15 16:40:02 +08:00 committed by Vacant2333
parent 6dea12190e
commit a6de63740b
7 changed files with 26 additions and 26 deletions

View File

@ -12,8 +12,8 @@ import (
"github.com/karmada-io/karmada/operator/pkg/util/apiclient"
)
// EnsureWebhookconfiguration creates karmada webhook mutatingWebhookConfiguration and validatingWebhookConfiguration
func EnsureWebhookconfiguration(client clientset.Interface, namespace, name, caBundle string) error {
// EnsureWebhookConfiguration creates karmada webhook mutatingWebhookConfiguration and validatingWebhookConfiguration
func EnsureWebhookConfiguration(client clientset.Interface, namespace, name, caBundle string) error {
if err := mutatingWebhookConfiguration(client, namespace, name, caBundle); err != nil {
return err
}

View File

@ -3,7 +3,6 @@ package tasks
import (
"errors"
"fmt"
"time"
"k8s.io/klog/v2"
@ -104,7 +103,7 @@ func runWaitKarmadaAPIServer(r workflow.RunData) error {
return errors.New("wait-KarmadaAPIServer task invoked with an invalid data struct")
}
waiter := apiclient.NewKarmadaWaiter(data.ControlplaneConfig(), data.RemoteClient(), time.Second*30)
waiter := apiclient.NewKarmadaWaiter(data.ControlplaneConfig(), data.RemoteClient(), componentBeReadyTimeout)
err := waiter.WaitForSomePods(karmadaApiserverLabels.String(), data.GetNamespace(), 1)
if err != nil {
@ -147,11 +146,11 @@ func runWaitKarmadaAggregatedAPIServer(r workflow.RunData) error {
return errors.New("wait-KarmadaAggregatedAPIServer task invoked with an invalid data struct")
}
waiter := apiclient.NewKarmadaWaiter(data.ControlplaneConfig(), data.RemoteClient(), time.Second*30)
waiter := apiclient.NewKarmadaWaiter(data.ControlplaneConfig(), data.RemoteClient(), componentBeReadyTimeout)
err := waiter.WaitForSomePods(karmadaAggregatedAPIServerLabels.String(), data.GetNamespace(), 1)
if err != nil {
return fmt.Errorf("waiting for karmada-apiserver to ready timeout, err: %w", err)
return fmt.Errorf("waiting for karmada-aggregated-apiserver to ready timeout, err: %w", err)
}
klog.V(2).InfoS("[wait-KarmadaAggregatedAPIServer] the karmada-aggregated-apiserver is ready", "karmada", klog.KObj(data))

View File

@ -3,7 +3,6 @@ package tasks
import (
"errors"
"fmt"
"time"
"k8s.io/klog/v2"
@ -72,12 +71,12 @@ func runWaitEtcd(r workflow.RunData) error {
return errors.New("wait-etcd task invoked with an invalid data struct")
}
waiter := apiclient.NewKarmadaWaiter(data.ControlplaneConfig(), data.RemoteClient(), time.Second*30)
waiter := apiclient.NewKarmadaWaiter(data.ControlplaneConfig(), data.RemoteClient(), componentBeReadyTimeout)
// wait etcd, karmada apiserver and aggregated apiserver to ready
// as long as a replica of pod is ready, we consider the service available.
if err := waiter.WaitForSomePods(etcdLabels.String(), data.GetNamespace(), 1); err != nil {
return fmt.Errorf("waiting for etcd to ready timeout, err: %w", err)
return fmt.Errorf("waiting for karmada-etcd to ready timeout, err: %w", err)
}
klog.V(2).InfoS("[wait-etcd] the etcd pods is ready", "karmada", klog.KObj(data))

View File

@ -8,7 +8,6 @@ import (
"path"
"regexp"
"strings"
"time"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@ -176,7 +175,7 @@ func runWebhookConfiguration(r workflow.RunData) error {
}
caBase64 := base64.StdEncoding.EncodeToString(cert.CertData())
return webhookconfiguration.EnsureWebhookconfiguration(
return webhookconfiguration.EnsureWebhookConfiguration(
data.KarmadaClient(),
data.GetNamespace(),
data.GetName(),
@ -200,7 +199,7 @@ func runAPIService(r workflow.RunData) error {
return fmt.Errorf("failed to apply aggregated APIService resource to karmada controlplane, err: %w", err)
}
waiter := apiclient.NewKarmadaWaiter(config, nil, time.Second*20)
waiter := apiclient.NewKarmadaWaiter(config, nil, componentBeReadyTimeout)
if err := apiclient.TryRunCommand(waiter.WaitForAPIService, 3); err != nil {
return fmt.Errorf("the APIService is unhealthy, err: %w", err)
}

View File

@ -14,12 +14,16 @@ import (
)
var (
// The timeout for wait each component be ready
// It includes the time for pulling the component image.
componentBeReadyTimeout = 120 * time.Second
etcdLabels = labels.Set{"karmada-app": constants.Etcd}
karmadaApiserverLabels = labels.Set{"karmada-app": constants.KarmadaAPIServer}
karmadaAggregatedAPIServerLabels = labels.Set{"karmada-app": constants.KarmadaAggregatedAPIServer}
kubeControllerManagerLabels = labels.Set{"karmada-app": constants.KubeControllerManager}
karmadaControllerManagerLabels = labels.Set{"karmada-app": constants.KarmadaControllerManager}
karmadaSchedulerLablels = labels.Set{"karmada-app": constants.KarmadaScheduler}
karmadaSchedulerLabels = labels.Set{"karmada-app": constants.KarmadaScheduler}
karmadaWebhookLabels = labels.Set{"karmada-app": constants.KarmadaWebhook}
)
@ -38,7 +42,7 @@ func runWaitApiserver(r workflow.RunData) error {
}
klog.V(4).InfoS("[check-apiserver-health] Running task", "karmada", klog.KObj(data))
waiter := apiclient.NewKarmadaWaiter(data.ControlplaneConfig(), data.RemoteClient(), time.Second*30)
waiter := apiclient.NewKarmadaWaiter(data.ControlplaneConfig(), data.RemoteClient(), componentBeReadyTimeout)
// check whether the karmada apiserver is health.
if err := apiclient.TryRunCommand(waiter.WaitForAPI, 3); err != nil {
@ -57,7 +61,7 @@ func NewWaitControlPlaneTask() workflow.Task {
Tasks: []workflow.Task{
newWaitControlPlaneSubTask("KubeControllerManager", kubeControllerManagerLabels),
newWaitControlPlaneSubTask("KarmadaControllerManager", karmadaControllerManagerLabels),
newWaitControlPlaneSubTask("KarmadaScheduler", karmadaSchedulerLablels),
newWaitControlPlaneSubTask("KarmadaScheduler", karmadaSchedulerLabels),
newWaitControlPlaneSubTask("KarmadaWebhook", karmadaWebhookLabels),
},
}
@ -87,7 +91,7 @@ func runWaitControlPlaneSubTask(component string, lables labels.Set) func(r work
return errors.New("wait-controlPlane task invoked with an invalid data struct")
}
waiter := apiclient.NewKarmadaWaiter(nil, data.RemoteClient(), time.Second*120)
waiter := apiclient.NewKarmadaWaiter(nil, data.RemoteClient(), componentBeReadyTimeout)
if err := waiter.WaitForSomePods(lables.String(), data.GetNamespace(), 1); err != nil {
return fmt.Errorf("waiting for %s to ready timeout, err: %w", component, err)
}

View File

@ -25,7 +25,7 @@ import (
var errAllocated = errors.New("provided port is already allocated")
// NewCRDsClient is to create a clientset ClientSet
// NewCRDsClient is to create a Clientset
func NewCRDsClient(c *rest.Config) (*crdsclient.Clientset, error) {
return crdsclient.NewForConfig(c)
}
@ -207,26 +207,26 @@ func PatchCustomResourceDefinition(client *crdsclient.Clientset, name string, da
}
// CreateOrUpdateStatefulSet creates a StatefulSet if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.
func CreateOrUpdateStatefulSet(client clientset.Interface, statefuleSet *appsv1.StatefulSet) error {
_, err := client.AppsV1().StatefulSets(statefuleSet.GetNamespace()).Create(context.TODO(), statefuleSet, metav1.CreateOptions{})
func CreateOrUpdateStatefulSet(client clientset.Interface, statefulSet *appsv1.StatefulSet) error {
_, err := client.AppsV1().StatefulSets(statefulSet.GetNamespace()).Create(context.TODO(), statefulSet, metav1.CreateOptions{})
if err != nil {
if !apierrors.IsAlreadyExists(err) {
return err
}
older, err := client.AppsV1().StatefulSets(statefuleSet.GetNamespace()).Get(context.TODO(), statefuleSet.GetName(), metav1.GetOptions{})
older, err := client.AppsV1().StatefulSets(statefulSet.GetNamespace()).Get(context.TODO(), statefulSet.GetName(), metav1.GetOptions{})
if err != nil {
return err
}
statefuleSet.ResourceVersion = older.ResourceVersion
_, err = client.AppsV1().StatefulSets(statefuleSet.GetNamespace()).Update(context.TODO(), statefuleSet, metav1.UpdateOptions{})
statefulSet.ResourceVersion = older.ResourceVersion
_, err = client.AppsV1().StatefulSets(statefulSet.GetNamespace()).Update(context.TODO(), statefulSet, metav1.UpdateOptions{})
if err != nil {
return err
}
}
klog.V(5).InfoS("Successfully created or updated statefulset", "statefulset", statefuleSet.GetName)
klog.V(5).InfoS("Successfully created or updated statefulset", "statefulset", statefulSet.GetName)
return nil
}
@ -248,7 +248,7 @@ func DeleteDeploymentIfHasLabels(client clientset.Interface, name, namespace str
return client.AppsV1().Deployments(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
}
// DeleteStatefulSetIfHasLabels deletes a StatefuleSet that exists the given labels.
// DeleteStatefulSetIfHasLabels deletes a StatefulSet that exists the given labels.
func DeleteStatefulSetIfHasLabels(client clientset.Interface, name, namespace string, ls labels.Set) error {
sts, err := client.AppsV1().StatefulSets(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {

View File

@ -19,8 +19,7 @@ func GetControlplaneEndpoint(address, port string) (string, error) {
if ip == nil {
return "", fmt.Errorf("invalid value `%s` given for address", address)
}
url := formatURL(ip.String(), port)
return url.String(), nil
return formatURL(ip.String(), port).String(), nil
}
// formatURL takes a host and a port string and creates a net.URL using https scheme