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

Use pullSecretPath to set GOOGLE_APPLICATION_CREDENTIALS #4147

Merged
merged 11 commits into from
Jun 10, 2020

Conversation

tejal29
Copy link
Contributor

@tejal29 tejal29 commented May 11, 2020

Fixes #3828

In this PR,

  1. rename pullSecret to pullSecretPath
  2. Use pullSecretPath specified in skaffold config to construct the GAC env variable.
  3. Display a warning message when default kaniko secret path is used.
  4. Added an integration test to specify kaniko secret name and secret path.

Output Changes
yes.

  1. A warning is shown on user terminal whenever default pull secret path is applied.
    This could add to noise. We should follow it up when we add pod health check and determine kaniko pod failure.

Cases where, kaniko secret name pullSecretName is specified, pullSecretPath which points to path with in the volume mounted secret or local path to create secret from is not specifief

  1. kaniko secret pullSecretName exists.
tejaldesai@tejaldesai-macbookpro2 kaniko (fix_kaniko_secret)../../out/skaffold dev -d gcr.io/tejal-test
Listing files to watch...
 - skaffold-example
Generating tags...
 - skaffold-example -> gcr.io/tejal-test/skaffold-example:v1.9.0-21-g897b49bd2
Checking cache...
 - skaffold-example: Not found. Building
Checking for kaniko secret [default/e2esecret]...
WARN[0000] Setting secret keyfile path to kaniko-secret. If this is incorrect, please specify using config key `pullSecret`.
See https://skaffold.dev/docs/references/yaml/#build-cluster-pullSecret 
  1. kaniko secret pullSecretName does not exist and no pullSecretPath specified to create it from
Listing files to watch...
 - skaffold-example
Generating tags...
 - skaffold-example -> gcr.io/tejal-test/skaffold-example:v1.9.0-21-g897b49bd2-dirty
Checking cache...
 - skaffold-example: Not found. Building
Checking for kaniko secret [default/e2esecret-not-exists]...
Creating kaniko secret [default/e2esecret-not-exists]...
exiting dev mode because first build failed: setting up pull secret: secret e2esecret-not-exists does not exisit. No path specified to create it
  1. Kaniko secret specified using pullSecretName. pullSecretPath points to the path within the secret volume.
    skaffold.yaml
tejaldesai@tejaldesai-macbookpro2 kaniko (fix_kaniko_secret)head skaffold.yaml 
apiVersion: skaffold/v2beta3
kind: Config
build:
  artifacts:
    - image: skaffold-example
      kaniko:
        cache: {}
  cluster:
    pullSecretName: e2esecret-with-path
    pullSecretPath: kaniko-secret.json

Skaffold logs

../../out/skaffold dev -d gcr.io/k8s-skaffold
Listing files to watch...
 - skaffold-example
Generating tags...
 - skaffold-example -> gcr.io/k8s-skaffold/skaffold-example:v1.9.0-21-g897b49bd2-dirty
Checking cache...
 - skaffold-example: Not found. Building
Checking for kaniko secret [default/e2esecret-with-path]...
Building [skaffold-example]...


Kaniko Pod description

kubectl describe po/kaniko-8t24q
Name:         kaniko-8t24q
Namespace:    default
Priority:     0
Node:         gke-integration-tests-default-pool-b6e32cfb-hqj3/10.128.15.201
Start Time:   Mon, 11 May 2020 13:36:07 -0700
Labels:       skaffold-kaniko=skaffold-kaniko
Annotations:  kubernetes.io/limit-ranger: LimitRanger plugin set: cpu request for container kaniko; cpu request for init container kaniko-init-container
Status:       Running
IP:           10.32.6.48
Init Containers:
  ....
Containers:
  kaniko:
    Container ID:  d...
    Host Port:     <none>
    Args:
      --dockerfile
      Dockerfile
      --context
      dir:///kaniko/buildcontext
      --destination
      gcr.io/k8s-skaffold/skaffold-example:v1.9.0-21-g897b49bd2-dirty
      -v
      info
      --cache=true
    State:          Running
      Started:      Mon, 11 May 2020 13:36:12 -0700
    Ready:          True
    Restart Count:  0
    Requests:
      cpu:  100m
    Environment:
      GOOGLE_APPLICATION_CREDENTIALS:  /secret/kaniko-secret.json

…tegration test to test it. Add a warning message when default are used
@tejal29 tejal29 added the fixit label May 11, 2020
@tejal29 tejal29 requested a review from nkubala May 11, 2020 20:42
@tejal29 tejal29 requested review from nkubala and removed request for nkubala May 11, 2020 20:43
@tstromberg
Copy link
Contributor

/cc @yuwenma

@tejal29
Copy link
Contributor Author

tejal29 commented May 11, 2020

/cc @prary Would be able to try this branch? I want to make sure we don't break your existing workflow with this change.

@tejal29
Copy link
Contributor Author

tejal29 commented May 11, 2020

Hold off merging until @prary can verify.

@codecov
Copy link

codecov bot commented May 11, 2020

Codecov Report

Merging #4147 into master will increase coverage by 0.02%.
The diff coverage is 90.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4147      +/-   ##
==========================================
+ Coverage   71.93%   71.95%   +0.02%     
==========================================
  Files         322      322              
  Lines       12313    12328      +15     
==========================================
+ Hits         8857     8871      +14     
- Misses       2896     2897       +1     
  Partials      560      560              
Impacted Files Coverage Δ
pkg/skaffold/schema/latest/config.go 100.00% <ø> (ø)
pkg/skaffold/schema/defaults/defaults.go 90.72% <75.00%> (ø)
pkg/skaffold/build/cluster/secret.go 41.53% <86.66%> (+5.33%) ⬆️
pkg/skaffold/build/cluster/pod.go 87.84% <100.00%> (+0.27%) ⬆️
pkg/skaffold/schema/v2beta4/upgrade.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7731b62...f5db1db. Read the comment docs.

return nil, fmt.Errorf("checking for existing kaniko secret: %w", err)
if _, err := secrets.Get(b.PullSecretName, metav1.GetOptions{}); err != nil {
color.Default.Fprintf(out, "Creating kaniko secret [%s/%s]...\n", b.Namespace, b.PullSecretName)
if b.PullSecret == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug to me - why don't we fall back to default pullsecret name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pullSecretName and pullSecret are two different configs

  1. pullSecretName is used to indicate the secret name. The default is kaniko-secret and is only set if pullSecret is specified.
  2. pullSecret refers to secret file path.

With this PR, pullSecret is used for a dual purpose.

  1. To create a secret if it does not exist from the file specified in this value
  2. To set GOOGLE_APPLICATION_CREDENTAILS env variable to this path when secret exists.

A bunch of tekton users, create secrets one time using a command like below.
See Additional Information in linked issue
A way to specify which path the secret lies at when using a secret is created using command if secret already exists.

kubectl create secret generic kaniko-secret --from-file=/Users/tejaldesai/workspace/keys/my-key.json

If a secret already exists, we should set the GOOGLE_APPLICATION_CREDENTAILS to path within the volume.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like pullSecret should be renamed to pullSecretPath.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! Renamed pullSecret to pullSecretPath

}
if b.PullSecret == "" {
// TODO: Remove the warning when pod health check can display pod failure errors.
logrus.Warnf("Setting secret keyfile path to %s. If this is incorrect, please specify using config key `pullSecret`.\nSee https://skaffold.dev/docs/references/yaml/#build-cluster-pullSecret", defaultKanikoSecretPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really want a warning here? I think a debug level is sufficient, as the user should only see this when there is something wrong. For those users who have 100% right with the default value, this just adds extra noise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does add to extra noise. However, it is not documented very well that skaffold expects the secret to be at path kaniko-secret when creating a secret.
Untill, we can provide an actionable error, i feel the noise is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be pullSecretPath (not pullSecret) in the message, right?

@chanseokoh
Copy link
Member

Just a thought: I presume there's a history for the name pullSecret. Although the skaffold.yaml reference documents that it's "for pulling base images and pushing the final image", but I've been thinking this can be confusing to some people. For example, #3828 was about pushing a final image to GCR.

@tejal29 tejal29 force-pushed the fix_kaniko_secret branch from fc23a32 to 51d02c1 Compare May 11, 2020 21:51
@prary
Copy link
Contributor

prary commented May 12, 2020

Hold off merging until @prary can verify.

will verify and update you guys asap.

@tejal29
Copy link
Contributor Author

tejal29 commented May 14, 2020

@prary ping! Can you please try this out? Let me know if i can help verify.

Thanks
Tejal

@prary
Copy link
Contributor

prary commented May 16, 2020

Hi @tejal29
I did try it but it failed, my workspace broke in middle hence reason for failure is unknown. I will get back to you with proper analysis once workspace issue is resolved, apologies for the delay.

Thanks for informing about this PR.

pkg/skaffold/build/cluster/pod.go Show resolved Hide resolved
return nil, fmt.Errorf("checking for existing kaniko secret: %w", err)
if _, err := secrets.Get(b.PullSecretName, metav1.GetOptions{}); err != nil {
color.Default.Fprintf(out, "Creating kaniko secret [%s/%s]...\n", b.Namespace, b.PullSecretName)
if b.PullSecret == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like pullSecret should be renamed to pullSecretPath.

pkg/skaffold/build/cluster/secret_test.go Outdated Show resolved Hide resolved
@kiran0707
Copy link

Hi,
Tested the change on behalf of @prary . It worked fine... the usual . it didnt break anything.

There is one thing that we have been seeing for past few skaffold versions.
At end of skaffold build, it tries to get the image ( i think for verifying whether image was pushed ), this thing results in error if this file $USERS_HOME/.docker/config.json is missing.

@tejal29
Copy link
Contributor Author

tejal29 commented May 27, 2020

Thanks @kiran0707 Will look into this.

@pull-request-size pull-request-size bot added size/L and removed size/M labels May 29, 2020
@tstromberg
Copy link
Contributor

Code looks good. Please check the PR title and description for accuracy.

@tejal29 tejal29 changed the title Use pullSecret to set GOOGLE_APPLICATION_CREDENTIALS or Warn with default set Use pullSecretPath to set GOOGLE_APPLICATION_CREDENTIALS Jun 1, 2020
@tejal29
Copy link
Contributor Author

tejal29 commented Jun 1, 2020

Code looks good. Please check the PR title and description for accuracy.

done. Can you take a look again.
Thanks

@tejal29 tejal29 dismissed balopat’s stale review June 10, 2020 18:41

addressed comments

@tejal29 tejal29 added the kokoro:run runs the kokoro jobs on a PR label Jun 10, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jun 10, 2020
@tejal29 tejal29 merged commit d97c88f into GoogleContainerTools:master Jun 10, 2020
@tejal29 tejal29 deleted the fix_kaniko_secret branch April 15, 2021 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

G_A_C in GKE Tekton pipeline: open /secret/kaniko-secret: no such file or directory
8 participants