Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Fix secrets CLI option (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmgot authored Apr 10, 2018
1 parent fa24587 commit 30da457
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
8 changes: 8 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ get-python-metadata:
get-python-metadata-verify:
kubeless function call get-python-metadata |egrep hello.world

get-python-secrets:
kubectl create secret generic test-secret --from-literal=key=MY_KEY || true
kubeless function deploy get-python-secrets --runtime python2.7 --handler helloget.foo --from-file python/helloget.py --secrets test-secret

get-python-secrets-verify:
$(eval pod := $(shell kubectl get pod -l function=get-python-secrets -o go-template -o custom-columns=:metadata.name --no-headers=true))
kubectl exec -it $(pod) cat /test-secret/key | egrep "MY_KEY"

get-ruby:
kubeless function deploy get-ruby --runtime ruby2.4 --handler helloget.foo --from-file ruby/helloget.rb

Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,14 +734,14 @@ func getRuntimeVolumeMount(name string) v1.VolumeMount {
func populatePodSpec(funcObj *kubelessApi.Function, lr *langruntime.Langruntimes, podSpec *v1.PodSpec, runtimeVolumeMount v1.VolumeMount) error {
depsVolumeName := funcObj.ObjectMeta.Name + "-deps"
result := podSpec
result.Volumes = []v1.Volume{
{
result.Volumes = append(podSpec.Volumes,
v1.Volume{
Name: runtimeVolumeMount.Name,
VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{},
},
},
{
v1.Volume{
Name: depsVolumeName,
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
Expand All @@ -751,7 +751,7 @@ func populatePodSpec(funcObj *kubelessApi.Function, lr *langruntime.Langruntimes
},
},
},
}
)
// prepare init-containers if some function is specified
if funcObj.Spec.Function != "" {
fileName, err := getFileName(funcObj.Spec.Handler, funcObj.Spec.FunctionContentType, funcObj.Spec.Runtime, lr)
Expand Down
26 changes: 26 additions & 0 deletions pkg/utils/k8sutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,32 @@ func TestEnsureDeployment(t *testing.T) {
if len(dpm.Spec.Template.Spec.InitContainers) != 0 {
t.Error("Unexpected init containers")
}

// It should include existing volumes
f10 := getDefaultFunc("func10", ns)
f10.Spec.Deployment.Spec.Template.Spec.Volumes = []v1.Volume{
{
Name: "test",
VolumeSource: v1.VolumeSource{},
},
}
f10.Spec.Deployment.Spec.Template.Spec.Containers[0].VolumeMounts = []v1.VolumeMount{
{
Name: "test",
MountPath: "/tmp/test",
},
}
err = EnsureFuncDeployment(clientset, f10, or, lr, "")
dpm, err = clientset.ExtensionsV1beta1().Deployments(ns).Get("func10", metav1.GetOptions{})
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if dpm.Spec.Template.Spec.Volumes[0].Name != "test" {
t.Error("Should maintain volumen test")
}
if dpm.Spec.Template.Spec.Containers[0].VolumeMounts[0].Name != "test" {
t.Error("Should maintain volumen test")
}
}

func fakeRESTClient(f func(req *http.Request) (*http.Response, error)) *restFake.RESTClient {
Expand Down
5 changes: 5 additions & 0 deletions tests/integration-tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ load ../script/libtest
deploy_function get-go-deps
deploy_function timeout-go
deploy_function get-python-metadata
deploy_function get-python-secrets
deploy_function post-python
deploy_function post-python-custom-port
deploy_function post-nodejs
Expand Down Expand Up @@ -176,6 +177,10 @@ load ../script/libtest
verify_function get-python-metadata
kubeless_function_delete get-python-metadata
}
@test "Test function: get-python-secrets" {
verify_function get-python-secrets
kubeless_function_delete get-python-secrets
}
@test "Test no-errors" {
if kubectl logs -n kubeless -l kubeless=controller | grep "level=error"; then
echo "Found errors in the controller logs"
Expand Down

0 comments on commit 30da457

Please sign in to comment.