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

Add PullSecretMountPath to ClusterDetails #2975

Merged
merged 4 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions docs/content/en/schemas/v1beta16.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@
"description": "path to the Google Cloud service account secret key file.",
"x-intellij-html-description": "path to the Google Cloud service account secret key file."
},
"pullSecretMountPath": {
"type": "string",
"description": "path the pull secret will be mounted at within the running container.",
"x-intellij-html-description": "path the pull secret will be mounted at within the running container."
},
"pullSecretName": {
"type": "string",
"description": "name of the Kubernetes secret for pulling the files from the build context and pushing the final image. If given, the secret needs to contain the Google Cloud service account secret key under the key `kaniko-secret`.",
Expand All @@ -496,6 +501,7 @@
"HTTPS_PROXY",
"pullSecret",
"pullSecretName",
"pullSecretMountPath",
"namespace",
"timeout",
"dockerConfig",
Expand Down
7 changes: 4 additions & 3 deletions pkg/skaffold/build/cluster/sources/localdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func TestPod(t *testing.T) {
},
},
clusterDetails: &latest.ClusterDetails{
Namespace: "ns",
PullSecretName: "secret",
Resources: reqs,
Namespace: "ns",
PullSecretName: "secret",
PullSecretMountPath: "/secret",
Resources: reqs,
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/cluster/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func podTemplate(clusterDetails *latest.ClusterDetails, artifact *latest.KanikoA

// Add secret for pull secret
if clusterDetails.PullSecretName != "" {
addSecretVolume(pod, constants.DefaultKanikoSecretName, "/secret", clusterDetails.PullSecretName)
addSecretVolume(pod, constants.DefaultKanikoSecretName, clusterDetails.PullSecretMountPath, clusterDetails.PullSecretName)
}

// Add host path volume for cache
Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/build/cluster/sources/sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func TestPodTemplate(t *testing.T) {
{
description: "with docker config",
initial: &latest.ClusterDetails{
PullSecretName: "pull-secret",
PullSecretName: "pull-secret",
PullSecretMountPath: "/secret",
DockerConfig: &latest.DockerConfig{
SecretName: "docker-cfg",
Path: "/kaniko/.docker",
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
DefaultKanikoCacheDirMountPath = "/cache"
DefaultKanikoDockerConfigSecretName = "docker-cfg"
DefaultKanikoDockerConfigPath = "/kaniko/.docker"
DefaultKanikoSecretMountPath = "/secret"

DefaultBusyboxImage = "busybox"

Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/schema/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func setDefaultClusterTimeout(cluster *latest.ClusterDetails) error {
}

func setDefaultClusterPullSecret(cluster *latest.ClusterDetails) error {
cluster.PullSecretMountPath = valueOrDefault(cluster.PullSecretMountPath, constants.DefaultKanikoSecretMountPath)
priyawadhwa marked this conversation as resolved.
Show resolved Hide resolved
if cluster.PullSecret != "" {
absPath, err := homedir.Expand(cluster.PullSecret)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions pkg/skaffold/schema/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ func TestSetDefaultsOnCluster(t *testing.T) {

t.CheckNoError(err)
t.CheckDeepEqual(constants.DefaultKanikoSecretName, cfg.Build.Cluster.PullSecretName)
t.CheckDeepEqual(constants.DefaultKanikoSecretMountPath, cfg.Build.Cluster.PullSecretMountPath)
Copy link
Member

Choose a reason for hiding this comment

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

Add a test for when the secret is optional and make sure PullSecretMountPath is not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By "when the secret is optional" do you mean when PullSecret and PullSecretName are not set?

Copy link
Member

Choose a reason for hiding this comment

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

yes i think that what @prary accomplished in #2910.


// pull secret mount path set
path := "/path"
cfg = &latest.SkaffoldConfig{
Pipeline: latest.Pipeline{
Build: latest.BuildConfig{
BuildType: latest.BuildType{
Cluster: &latest.ClusterDetails{
PullSecret: "path/to/pull/secret",
PullSecretMountPath: path,
},
},
},
},
}

err = Set(cfg)
t.CheckNoError(err)
t.CheckDeepEqual(constants.DefaultKanikoSecretName, cfg.Build.Cluster.PullSecretName)
t.CheckDeepEqual(path, cfg.Build.Cluster.PullSecretMountPath)

// default docker config
cfg.Pipeline.Build.BuildType.Cluster.DockerConfig = &latest.DockerConfig{}
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ type ClusterDetails struct {
// Defaults to `kaniko-secret`.
PullSecretName string `yaml:"pullSecretName,omitempty"`

// PullSecretMountPath is the path the pull secret will be mounted at within the running container.
PullSecretMountPath string `yaml:"pullSecretMountPath,omitempty"`

// Namespace is the Kubernetes namespace.
// Defaults to current namespace in Kubernetes configuration.
Namespace string `yaml:"namespace,omitempty"`
Expand Down
15 changes: 8 additions & 7 deletions pkg/skaffold/schema/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestParseConfig(t *testing.T) {
description: "Minimal Kaniko config",
config: minimalKanikoConfig,
expected: config(
withClusterBuild("", "default", "", "20m",
withClusterBuild("", "/secret", "default", "", "20m",
withGitTagger(),
withKanikoArtifact("image1", "./examples/app1", "Dockerfile", "demo"),
),
Expand All @@ -184,7 +184,7 @@ func TestParseConfig(t *testing.T) {
description: "Complete Kaniko config",
config: completeKanikoConfig,
expected: config(
withClusterBuild("secret-name", "nskaniko", "/secret.json", "120m",
withClusterBuild("secret-name", "/secret", "nskaniko", "/secret.json", "120m",
withGitTagger(),
withDockerConfig("config-name", "/kaniko/.docker"),
withKanikoArtifact("image1", "./examples/app1", "Dockerfile", ""),
Expand Down Expand Up @@ -283,13 +283,14 @@ func withGoogleCloudBuild(id string, ops ...func(*latest.BuildConfig)) func(*lat
}
}

func withClusterBuild(secretName, namespace, secret string, timeout string, ops ...func(*latest.BuildConfig)) func(*latest.SkaffoldConfig) {
func withClusterBuild(secretName, mountPath, namespace, secret string, timeout string, ops ...func(*latest.BuildConfig)) func(*latest.SkaffoldConfig) {
return func(cfg *latest.SkaffoldConfig) {
b := latest.BuildConfig{BuildType: latest.BuildType{Cluster: &latest.ClusterDetails{
PullSecretName: secretName,
Namespace: namespace,
PullSecret: secret,
Timeout: timeout,
PullSecretName: secretName,
Namespace: namespace,
PullSecret: secret,
PullSecretMountPath: mountPath,
Timeout: timeout,
}}}
for _, op := range ops {
op(&b)
Expand Down