Skip to content

Commit

Permalink
Make k8s bootstrap log messages less verbose;
Browse files Browse the repository at this point in the history
  • Loading branch information
ycliuhw committed Sep 8, 2021
1 parent d7924df commit 56e7335
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 27 deletions.
14 changes: 7 additions & 7 deletions caas/kubernetes/provider/bootstrap.go
Expand Up @@ -680,7 +680,7 @@ func (c *controllerStack) createControllerSecretSharedSecret() error {
return errors.Trace(err)
}
secret.Data[c.fileNameSharedSecret] = []byte(si.SharedSecret)
logger.Debugf("ensuring shared secret: \n%+v", secret)
logger.Tracef("ensuring shared secret: \n%+v", secret)
c.addCleanUp(func() {
logger.Debugf("deleting %q shared-secret", secret.Name)
_ = c.broker.deleteSecret(secret.GetName(), secret.GetUID())
Expand Down Expand Up @@ -740,7 +740,7 @@ func (c *controllerStack) createControllerSecretServerPem() error {
}
secret.Data[c.fileNameSSLKey] = []byte(mongo.GenerateSSLKey(si.Cert, si.PrivateKey))

logger.Debugf("ensuring server.pem secret: \n%+v", secret)
logger.Tracef("ensuring server.pem secret: \n%+v", secret)
c.addCleanUp(func() {
logger.Debugf("deleting %q server.pem", secret.Name)
_ = c.broker.deleteSecret(secret.GetName(), secret.GetUID())
Expand All @@ -757,15 +757,15 @@ func (c *controllerStack) ensureControllerConfigmapBootstrapParams() error {
if err != nil {
return errors.Trace(err)
}
logger.Debugf("bootstrapParams file content: \n%s", string(bootstrapParamsFileContent))
logger.Tracef("bootstrapParams file content: \n%s", string(bootstrapParamsFileContent))

cm, err := c.getControllerConfigMap()
if err != nil {
return errors.Trace(err)
}
cm.Data[c.fileNameBootstrapParams] = string(bootstrapParamsFileContent)

logger.Debugf("creating bootstrap-params configmap: \n%+v", cm)
logger.Tracef("creating bootstrap-params configmap: \n%+v", cm)

cleanUp, err := c.broker.ensureConfigMap(cm)
c.addCleanUp(func() {
Expand All @@ -780,15 +780,15 @@ func (c *controllerStack) ensureControllerConfigmapAgentConf() error {
if err != nil {
return errors.Trace(err)
}
logger.Debugf("agentConfig file content: \n%s", string(agentConfigFileContent))
logger.Tracef("agentConfig file content: \n%s", string(agentConfigFileContent))

cm, err := c.getControllerConfigMap()
if err != nil {
return errors.Trace(err)
}
cm.Data[c.fileNameAgentConf] = string(agentConfigFileContent)

logger.Debugf("ensuring agent.conf configmap: \n%+v", cm)
logger.Tracef("ensuring agent.conf configmap: \n%+v", cm)
cleanUp, err := c.broker.ensureConfigMap(cm)
c.addCleanUp(func() {
logger.Debugf("deleting %q template-agent.conf", cm.Name)
Expand Down Expand Up @@ -896,7 +896,7 @@ func (c *controllerStack) createControllerStatefulset() error {
return errors.Trace(err)
}

logger.Debugf("creating controller statefulset: \n%+v", spec)
logger.Tracef("creating controller statefulset: \n%+v", spec)
c.addCleanUp(func() {
logger.Debugf("deleting %q statefulset", spec.Name)
_ = c.broker.deleteStatefulSet(spec.Name)
Expand Down
2 changes: 1 addition & 1 deletion controller/config.go
Expand Up @@ -861,8 +861,8 @@ func validateCAASImageRepo(imageRepo string) (string, error) {
if err != nil {
return "", errors.Trace(err)
}
defer func() { _ = r.Close() }()
*imageDetails = r.ImageRepoDetails()
func() { _ = r.Close() }()
}
return imageDetails.String(), nil
}
Expand Down
2 changes: 1 addition & 1 deletion controller/config_test.go
Expand Up @@ -645,7 +645,7 @@ func (s *ConfigSuite) TestCAASImageRepo(c *gc.C) {
"auth": "%s",
"repository": "ghcr.io/test-account"
}`, base64.StdEncoding.EncodeToString([]byte("username:pwd"))),
expected: "test-account"},
expected: "ghcr.io/test-account"},
} {
if imageRepo.expected == "" {
imageRepo.expected = imageRepo.content
Expand Down
4 changes: 4 additions & 0 deletions docker/auth.go
Expand Up @@ -94,11 +94,13 @@ type ImageRepoDetails struct {
ServerAddress string `json:"serveraddress,omitempty" yaml:"serveraddress,omitempty"`
}

// AuthEqual compares if the provided one equals to current repository detail.
func (rid ImageRepoDetails) AuthEqual(r ImageRepoDetails) bool {
return reflect.DeepEqual(rid.BasicAuthConfig, r.BasicAuthConfig) &&
reflect.DeepEqual(rid.TokenAuthConfig, r.TokenAuthConfig)
}

// IsPrivate checks if the repository detail is private.
func (rid ImageRepoDetails) IsPrivate() bool {
return !rid.BasicAuthConfig.Empty() || !rid.TokenAuthConfig.Empty()
}
Expand Down Expand Up @@ -155,6 +157,8 @@ func (rid *ImageRepoDetails) init() error {
}
return nil
}

// Empty checks if the auth information is empty.
func (rid ImageRepoDetails) Empty() bool {
return rid == ImageRepoDetails{}
}
Expand Down
35 changes: 17 additions & 18 deletions docker/registry/acr.go
Expand Up @@ -24,6 +24,7 @@ func newAzureContainerRegistry(repoDetails docker.ImageRepoDetails, transport ht
return &azureContainerRegistry{c}
}

// Match checks if the repository details matches current provider format.
func (c *azureContainerRegistry) Match() bool {
c.prepare()
return strings.Contains(c.repoDetails.ServerAddress, "azurecr.io")
Expand All @@ -43,26 +44,24 @@ func getUserNameFromAuthForACR(auth string) (string, error) {

func (c *azureContainerRegistry) WrapTransport() error {
transport := c.client.Transport
if c.repoDetails.IsPrivate() {
if !c.repoDetails.TokenAuthConfig.Empty() {
username := c.repoDetails.Username
if username == "" {
var err error
username, err = getUserNameFromAuthForACR(c.repoDetails.Auth)
if err != nil {
return errors.Trace(err)
}
if c.repoDetails.IsPrivate() && !c.repoDetails.TokenAuthConfig.Empty() {
username := c.repoDetails.Username
if username == "" {
var err error
username, err = getUserNameFromAuthForACR(c.repoDetails.Auth)
if err != nil {
return errors.Trace(err)
}
password := c.repoDetails.Password
if password == "" {
password = c.repoDetails.IdentityToken
}
transport = newTokenTransport(
transport,
username, password,
"", "",
)
}
password := c.repoDetails.Password
if password == "" {
password = c.repoDetails.IdentityToken
}
transport = newTokenTransport(
transport,
username, password,
"", "",
)
}
c.client.Transport = newErrorTransport(transport)
return nil
Expand Down
2 changes: 2 additions & 0 deletions docker/registry/base.go
Expand Up @@ -76,6 +76,7 @@ func (c *baseClient) prepare() {
}
}

// Match checks if the repository details matches current provider format.
func (c *baseClient) Match() bool {
return false
}
Expand Down Expand Up @@ -109,6 +110,7 @@ func (c *baseClient) WrapTransport() error {
return nil
}

// DecideBaseURL decides the API url to use.
func (c *baseClient) DecideBaseURL() error {
addr := c.repoDetails.ServerAddress
if addr == "" {
Expand Down
2 changes: 2 additions & 0 deletions docker/registry/dockerhub.go
Expand Up @@ -26,11 +26,13 @@ func newDockerhub(repoDetails docker.ImageRepoDetails, transport http.RoundTripp
return &dockerhub{c}
}

// Match checks if the repository details matches current provider format.
func (c *dockerhub) Match() bool {
c.prepare()
return c.repoDetails.ServerAddress == "" || strings.Contains(c.repoDetails.ServerAddress, "docker.io")
}

// DecideBaseURL decides the API url to use.
func (c *dockerhub) DecideBaseURL() error {
c.repoDetails.ServerAddress = dockerServerAddress
if err := c.baseClient.DecideBaseURL(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions docker/registry/ecr.go
Expand Up @@ -21,6 +21,7 @@ func newElasticContainerRegistry(repoDetails docker.ImageRepoDetails, transport
return &elasticContainerRegistry{c}
}

// Match checks if the repository details matches current provider format.
func (c *elasticContainerRegistry) Match() bool {
c.prepare()
return strings.Contains(c.repoDetails.ServerAddress, "ecr.aws")
Expand Down
1 change: 1 addition & 0 deletions docker/registry/gcr.go
Expand Up @@ -21,6 +21,7 @@ func newGoogleContainerRegistry(repoDetails docker.ImageRepoDetails, transport h
return &googleContainerRegistry{c}
}

// Match checks if the repository details matches current provider format.
func (c *googleContainerRegistry) Match() bool {
c.prepare()
return strings.Contains(c.repoDetails.ServerAddress, "gcr.io")
Expand Down
1 change: 1 addition & 0 deletions docker/registry/github.go
Expand Up @@ -22,6 +22,7 @@ func newGithubContainerRegistry(repoDetails docker.ImageRepoDetails, transport h
return &githubContainerRegistry{c}
}

// Match checks if the repository details matches current provider format.
func (c *githubContainerRegistry) Match() bool {
c.prepare()
return strings.Contains(c.repoDetails.ServerAddress, "ghcr.io")
Expand Down
1 change: 1 addition & 0 deletions docker/registry/gitlab.go
Expand Up @@ -19,6 +19,7 @@ func newGitlabContainerRegistry(repoDetails docker.ImageRepoDetails, transport h
return &gitlabContainerRegistry{c}
}

// Match checks if the repository details matches current provider format.
func (c *gitlabContainerRegistry) Match() bool {
c.prepare()
return strings.Contains(c.repoDetails.ServerAddress, "registry.gitlab.com")
Expand Down
1 change: 1 addition & 0 deletions docker/registry/quay_io.go
Expand Up @@ -21,6 +21,7 @@ func newQuayContainerRegistry(repoDetails docker.ImageRepoDetails, transport htt
return &quayContainerRegistry{c}
}

// Match checks if the repository details matches current provider format.
func (c *quayContainerRegistry) Match() bool {
c.prepare()
return strings.Contains(c.repoDetails.ServerAddress, "quay.io")
Expand Down

0 comments on commit 56e7335

Please sign in to comment.