-
Notifications
You must be signed in to change notification settings - Fork 772
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 support for file based secret #1007
Conversation
/assign cdrage |
@hangyan Please separate the commits between code change and vendor update so we can review! |
@cdrage Done. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @hangyan I see some still work-in-progress code, is this ready for review?
pkg/loader/compose/v3.go
Outdated
@@ -117,6 +117,7 @@ func parseV3(files []string) (kobject.KomposeObject, error) { | |||
} | |||
} | |||
} | |||
log.Debugf("fuck %+v", config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be removed 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdrage So sorry for this , totally forgot this debug info.
pkg/kobject/kobject.go
Outdated
type OldSecretConfig struct { | ||
File string | ||
} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented out code
pkg/loader/compose/v3.go
Outdated
} | ||
|
||
}*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented out code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdrage This is ready for review. But i have started too long ago and forgot to remove some useless code before this review. Sorry about that! Will be more carefully about this in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this code is no longer needed, please remove the commented out code 👍 @hangyan
80648b6
to
75855dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have to test this out, but other than a few comments, the code is great!
Just add more comments please to the code so future programmers can better understand what is happening, otherwise, looks amazing to me!
pkg/loader/compose/v3.go
Outdated
} | ||
|
||
}*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this code is no longer needed, please remove the commented out code 👍 @hangyan
if config.File != "" { | ||
data, err := GetSecretDataFromFile(config.File, k.Opt) | ||
if err != nil { | ||
log.Fatal("unable to read secret from file:", config.File) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add spacing after "file:"
} | ||
objects = append(objects, secret) | ||
} else { | ||
log.Warnf("External secrets %s is not supported by now - ignoring", name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small grammar mistake, should be "is not currently supported"
} | ||
} | ||
return volumeMounts, volumes | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you able to comment on some of the code above as to what's happening?
if komposeObject.Secrets != nil { | ||
secrets, err := k.CreateSecrets(komposeObject) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "create secrets error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add something different such as "Unable to create secrets" or something more descriptive? Not too sure what type of error message to add.
@@ -449,6 +531,10 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( | |||
useHostPath = true | |||
} | |||
|
|||
secretsVolumeMounts, secretsVolumes := k.ConfigSecretVolumes(name, service) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment above here explaining that we are adding secrets to volumes
Progress @hangyan ? |
@cdrage Sorry, been very busy these days on my work. Working on this now. |
@cdrage Updated |
conflict resolved |
@cdrage is this good? will be merged? |
|
||
volMount := api.VolumeMount{ | ||
Name: vol.Name, | ||
MountPath: "/run/secrets", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hangyan
This shouldn't be MountPath: "/run/secrets/" + vol.Name,
???
Because without the MountPath targeting to the secret, it gives a error:
RunContainerError: failed to start container "f97d9e9354548939d15acae70758347538426fbb05c80f2a5cd316dc67e7bf58":
Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:359:
container init caused \"rootfs_linux.go:54:
mounting \\\"/opt/rke/var/lib/kubelet/pods/516c135b-bce8-11e8-8714-005056ae708d/volumes/kubernetes.io~secret/default-token-khnzc\\\"
to rootfs \\\"/var/lib/docker/overlay/60fb5d9a4007bf8e1889898df737b275cb77431351b9168ab4d629fbcdf065b5/merged\\\"
at \\\"/var/lib/docker/overlay/60fb5d9a4007bf8e1889898df737b275cb77431351b9168ab4d629fbcdf065b5/merged/run/secrets/kubernetes.io/serviceaccount\\\"
caused \\\"mkdir /var/lib/docker/overlay/60fb5d9a4007bf8e1889898df737b275cb77431351b9168ab4d629fbcdf065b5/merged/run/secrets/kubernetes.io: read-only file system\\\"\""
Just like in this issue: kubernetes/kubernetes#65835
And concating the secret name, it work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With some research i discover that:
kubernetes
kubectl create secret generic my_secret --from-literal=my_secret_key_1=my_secret_value_1 --from-literal=my_secret_key_2=my_secret_value_2
it create a file /run/secrets/my_secret/my_secret_key_1
(with the content my_secret_value_1
)
docker-compose/swarm
- with short syntax:
...
secrets:
- my_secret
secrets:
my_secret:
file: my_secret.txt
it create a file /run/secrets/my_secret
don't allow to be compatible with kubernetes
- with long syntax:
...
secrets:
- source: some_secret
target: my_secret/my_secret_key
secrets:
some_secret:
file: my_secret.txt
it create a file /run/secrets/my_secret/my_secret_key
allow to be compatible with kubernetes
I believe that this PR:
- shouldn't allow to use short-syntax, or if allow, to at least concat the secret name as directory (as my previous comment suggest to avoid the error).
- only allow long-syntax if has at least inside one directory to be compatible with kubernetes, or at least concat the secret name as directory
Maybe concat the secret name as directory (by default) for the path can be the solution!?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jvitor83 Sorry about the late response. I have re-checked the document of kubernetes and docker. I have different opinion on this problem. kompose is meant to translate compose to kubernetes as precision as possible. Because docker mount the secret to /run/secrets/<secret-name>
, so this path should be the same in kubernetes, not /run/secrets/<secret-name>/<key>
. I believe the right choice is to use subPath ( you can see a example in the issues link you provide)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it that "kompose is meant to translate compose to kubernetes as precision as possible", but it didn't work with the k8s generated!
The generated mapping gives error (mentioned before) and the pod didn't start!
By my understanding, the generated files should work in first place to then keep the translation as precise as possible.
I guess we should remove the short syntax once it is incompatible and don't allow to get the file at the same path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue link you provide has a solution in the end:subPath. I think it's a better solution, i haven't test it out, but I think it should work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hangyan
I am not understanding what you mean.
The thing is that this PR is generating:
volumeMounts:
- name: secret-name
mountPath: "/run/secrets"
which gives the error reported.
The issue (kubernetes/kubernetes#65835) was solved not because it put the subPath
, but because the directory was added to the mountPath. (I think the issue author have been mistaken)
If the kompose generate the k8s without the mountPath with a directory (with secret using short-syntax), it will give error on start. I have tested it with openjdk, dotnet and others. All gives the same error.
What you are suggesting to do?
If is to: "modify the code to add the subPath", it will continue to give the error.
I think we have to at least put some warning saying that secrets with short-syntax is not recommended and can gives error.
@hangyan , i create a PR ( https://github.com/hangyan/kompose/pull/3/files ) to your secret-support branch (PR) which:
|
@jvitor83 Great. Thanks very much. I will review this again ASAP. But since there are not so many active maintainers for this project, this PR may take a long time to be merged in. I'm afraid of you will have to build the binary yourself based on this branch. |
Already did it! |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
related to #296
Notes: