Skip to content

Commit f778e31

Browse files
amisevskibuziuk
authored andcommitted
Wait up to 5 seconds for ImagePullSecrets to be added to SA
In some clusters, adding ImagePullSecrets to a ServiceAccount can take a second or two. If the DevWorkspace Operator creates the workspace Deployment before this occurs, then once the pull secret is added the Deployment needs to roll out a new version, resulting in a delay in workspace start. To avoid this, if the ServiceAccount does not have any image pull secrets, we wait up to 5 seconds from the creation timestamp of the ServiceAccount before continuing. Signed-off-by: Angel Misevski <amisevsk@redhat.com>
1 parent 9b9d8fd commit f778e31

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/provision/workspace/pull_secret.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package workspace
1818
import (
1919
"context"
2020
"fmt"
21+
"time"
2122

2223
"github.com/devfile/devworkspace-operator/pkg/provision/sync"
2324
"k8s.io/apimachinery/pkg/types"
@@ -30,6 +31,10 @@ import (
3031
"sigs.k8s.io/controller-runtime/pkg/client"
3132
)
3233

34+
const (
35+
pullSecretCreationTimeout time.Duration = 5_000_000_000 // 5 seconds
36+
)
37+
3338
type PullSecretsProvisioningStatus struct {
3439
ProvisioningStatus
3540
v1alpha1.PodAdditions
@@ -70,6 +75,15 @@ func PullSecrets(clusterAPI sync.ClusterAPI, serviceAccountName, namespace strin
7075
}
7176
}
7277

78+
if len(serviceAccount.ImagePullSecrets) == 0 && serviceAccount.CreationTimestamp.Add(pullSecretCreationTimeout).After(time.Now()) {
79+
return PullSecretsProvisioningStatus{
80+
ProvisioningStatus: ProvisioningStatus{
81+
Requeue: true,
82+
Message: "Waiting for image pull secrets",
83+
},
84+
}
85+
}
86+
7387
dockerCfgs := serviceAccount.ImagePullSecrets
7488
for _, s := range secrets.Items {
7589
if s.Type == corev1.SecretTypeDockercfg || s.Type == corev1.SecretTypeDockerConfigJson {

0 commit comments

Comments
 (0)