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

Kaniko secret #2321

Closed
wants to merge 8 commits into from
Closed

Kaniko secret #2321

wants to merge 8 commits into from

Conversation

prary
Copy link
Contributor

@prary prary commented Jun 22, 2019

kaniko pull secret should be optional
Resolving issue #2190

@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label Jun 22, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jun 22, 2019
Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

Actually, this is not how we should implement the optionality.
The logic should be implemented in secret.go, here -- when both PullSecretName and PullSecret are empty then that should be fine.

@prary
Copy link
Contributor Author

prary commented Jun 23, 2019

This is how it should be right?

func setupPullSecret() {
	if b.PullSecret == "" {
		return func() {}, nil
        }
        rest of the secret creation code
}

@codecov
Copy link

codecov bot commented Jun 23, 2019

Codecov Report

Merging #2321 into master will decrease coverage by 0.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2321      +/-   ##
==========================================
- Coverage   61.86%   61.84%   -0.02%     
==========================================
  Files         186      186              
  Lines        8050     8052       +2     
==========================================
  Hits         4980     4980              
- Misses       2679     2681       +2     
  Partials      391      391
Impacted Files Coverage Δ
pkg/skaffold/build/cluster/cluster.go 18.91% <ø> (ø) ⬆️
pkg/skaffold/build/cluster/secret.go 0% <0%> (ø) ⬆️

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 6bd1d50...9dc22c8. Read the comment docs.

@dgageot
Copy link
Contributor

dgageot commented Jul 5, 2019

@prary could you add a unit test for the new code?

@prary
Copy link
Contributor Author

prary commented Jul 10, 2019

@prary could you add a unit test for the new code?

Sure I will add

@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label Jul 16, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jul 16, 2019
@tejal29
Copy link
Contributor

tejal29 commented Aug 16, 2019

@prary, Here is an example of creating a mock client and adding secrets

objs := make([]runtime.Object, len(test.deps))

// Create Secrets	
		objs := make([]runtime.Object, len(test.secrets))
			for i, s := range test.secrets {
				objs[i] = dep
			}
// Create a fake client with Secrets added
			client := fakekubeclientset.NewSimpleClientset(objs...)
// Pass the fake client to the method using it

actual, err := getDeployments(client, "test", labeller, time.Duration(200)*time.Second)

@tejal29
Copy link
Contributor

tejal29 commented Aug 16, 2019

In your case, you need to mock the function call to kubernetes.GetClientset() to actually return the fakeclient.

An example is here:

https://github.com/GoogleContainerTools/skaffold/blob/master/pkg/skaffold/kubernetes/portforward/resource_forwarder.go#L43

And In tests, you mock by :

https://github.com/GoogleContainerTools/skaffold/blob/master/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go#L347

pkg/skaffold/build/cluster/cluster.go Outdated Show resolved Hide resolved
pkg/skaffold/build/cluster/secret.go Outdated Show resolved Hide resolved
prary and others added 2 commits August 28, 2019 10:39
Co-Authored-By: Tejal Desai <tejal29@gmail.com>
@tejal29
Copy link
Contributor

tejal29 commented Aug 28, 2019

Unfortunately you ended up changing a file which does not have any test coverage. :(

In this case, the best way to test would be

  1. create a new test file secret_test.go
  2. create a testRunContext with ClusterDetails where b.PullSecret and b.PullSecretName is empty. Create a testBuilder
runCtx := &runcontext.RunContext{Cgf: latest.Pipeline{}}
testBuilder := NewBuilder(runCtx)
expectedFunc, expectedErr := testBuilder.setupPullSecret(ioutil.Discard)

See an example:

runCtx := &runcontext.RunContext{

you can add tests for

  1. when both are empty
  2. When b.PullSecret is empty

For test case 2, you will have to use instructions mentioned here #2321 (comment)

@tejal29
Copy link
Contributor

tejal29 commented Sep 4, 2019

I think @dgageot covered this #2321

@tejal29 tejal29 closed this Sep 4, 2019
@prary prary deleted the kaniko_secret branch September 9, 2019 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants