Merge pull request #1800 from niusmallnan/dev

Add retry backoff for starting network-policy controller
This commit is contained in:
Erik Wilson 2020-07-01 09:47:21 -07:00 committed by GitHub
commit 42f0b95ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,8 +8,12 @@ import (
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/retry"
)
func Run(ctx context.Context, nodeConfig *config.Node) error {
@ -28,6 +32,21 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
return err
}
// retry backoff to wait for the clusterrolebinding of user "system:k3s-controller"
retryBackoff := wait.Backoff{
Steps: 6,
Duration: 100 * time.Millisecond,
Factor: 3.0,
Cap: 30 * time.Second,
}
retryErr := retry.OnError(retryBackoff, errors.IsForbidden, func() error {
_, err := client.NetworkingV1().NetworkPolicies("").List(ctx, metav1.ListOptions{})
return err
})
if retryErr != nil {
return retryErr
}
npc, err := NewNetworkPolicyController(ctx.Done(), client, time.Minute, nodeConfig.AgentConfig.NodeName)
if err != nil {
return err