Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for webhook key to be present in filesystem #2312

Merged
merged 2 commits into from
Dec 20, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/http/pprof"
"os"
"path"
"strings"
"time"

Expand Down Expand Up @@ -46,6 +47,7 @@ import (
"github.com/elastic/cloud-on-k8s/pkg/dev"
"github.com/elastic/cloud-on-k8s/pkg/dev/portforward"
"github.com/elastic/cloud-on-k8s/pkg/utils/net"
"k8s.io/apimachinery/pkg/util/wait"
)

const (
Expand Down Expand Up @@ -322,7 +324,6 @@ func execute() {
os.Exit(1)
}
}

log.Info("Starting the manager", "uuid", operatorInfo.OperatorUUID,
"namespace", operatorNamespace, "version", operatorInfo.BuildInfo.Version,
"build_hash", operatorInfo.BuildInfo.Hash, "build_date", operatorInfo.BuildInfo.Date,
Expand Down Expand Up @@ -387,4 +388,26 @@ func setupWebhook(mgr manager.Manager, certRotation certificates.RotationParams,
log.Error(err, "unable to create webhook", "webhook", "Elasticsearch")
os.Exit(1)
}

// wait for the secret to be populated in the local filesystem before returning
interval := time.Second * 1
timeout := time.Second * 30
keyPath := path.Join(mgr.GetWebhookServer().CertDir, "tls.crt")
anyasabo marked this conversation as resolved.
Show resolved Hide resolved
anyasabo marked this conversation as resolved.
Show resolved Hide resolved
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
_, err := os.Stat(keyPath)
// err could be that the file does not exist, but also that permission was denied or something else
if os.IsNotExist(err) {
log.V(1).Info("Webhook certificate file not present on filesystem yet", "path", keyPath)
anyasabo marked this conversation as resolved.
Show resolved Hide resolved
return false, nil
} else if err != nil {
log.Error(err, "Error checking if webhook secret path exists", "path", keyPath)
return false, err
}
log.V(1).Info("Webhook certificate file present on filesystem", "path", keyPath)
return true, nil
})

if err != nil {
os.Exit(1)
}
}