Skip to content

Commit

Permalink
fix: correct EnvVarSource type in vvp model (#159)
Browse files Browse the repository at this point in the history
* fix: correct EnvVar type in vvp model

* revert test
  • Loading branch information
austince authored Jul 17, 2020
1 parent 4f98e8d commit 890a986
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
22 changes: 22 additions & 0 deletions api/v1beta2/vpdeployment_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ var _ = Describe("VpDeployment conversion", func() {
Kind: "JAR",
JarURI: "https://jars.com/peanut-butter",
},
Kubernetes: &VpKubernetesOptions{
Pods: &VpPodSpec{
EnvVars: []core.EnvVar{
{
Name: "TEST_ENV",
Value: "TEST_VALUE",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -94,6 +104,16 @@ var _ = Describe("VpDeployment conversion", func() {
Kind: "JAR",
JarURI: "https://jars.com/peanut-butter",
},
Kubernetes: &v1beta1.VpKubernetesOptions{
Pods: &v1beta1.VpPodSpec{
EnvVars: []core.EnvVar{
{
Name: "TEST_ENV",
Value: "TEST_VALUE",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -341,5 +361,7 @@ var _ = Describe("VpDeployment conversion", func() {
Expect(v2.Spec.Spec.MaxJobCreationAttempts).To(BeEquivalentTo(v2Clone.Spec.Spec.MaxJobCreationAttempts))
Expect(v2.Spec.Spec.Template.Metadata).To(BeEquivalentTo(v2Clone.Spec.Spec.Template.Metadata))
Expect(v2.Spec.Spec.Template.Spec).To(BeEquivalentTo(v2Clone.Spec.Spec.Template.Spec))
k8sSpec := v2.Spec.Spec.Template.Spec.Kubernetes
Expect(k8sSpec.Pods.EnvVars).To(BeEquivalentTo(v2Clone.Spec.Spec.Template.Spec.Kubernetes.Pods.EnvVars))
})
})
4 changes: 3 additions & 1 deletion pkg/vvp/appmanager-api/model_env_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

package appmanagerapi

import core "k8s.io/api/core/v1"

type EnvVar struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
ValueFrom *JsonNode `json:"valueFrom,omitempty"`
ValueFrom *core.EnvVarSource `json:"valueFrom,omitempty"`
}
36 changes: 35 additions & 1 deletion pkg/vvp/native_converters/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"github.com/fintechstudios/ververica-platform-k8s-operator/pkg/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"time"
)

Expand All @@ -20,7 +22,30 @@ var _ = Describe("Deployment", func() {
Spec: v1beta2.VpDeploymentSpec{
Template: &v1beta2.VpDeploymentTemplate{
Metadata: &v1beta2.VpDeploymentTemplateMetadata{},
Spec: &v1beta2.VpDeploymentTemplateSpec{},
Spec: &v1beta2.VpDeploymentTemplateSpec{
Kubernetes: &v1beta2.VpKubernetesOptions{
Pods: &v1beta2.VpPodSpec{
EnvVars: []core.EnvVar{
{
Name: "TEST_ENV",
Value: "TEST_VALUE",
},
{
Name: "API_KEY",
ValueFrom: &core.EnvVarSource{
SecretKeyRef: &core.SecretKeySelector{
LocalObjectReference: core.LocalObjectReference{
Name: "some-secret",
},
Key: "api-key",
Optional: pointer.BoolPtr(true),
},
},
},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -67,6 +92,15 @@ var _ = Describe("Deployment", func() {
Expect(err).ToNot(HaveOccurred())
Expect(dep.Spec).ToNot(BeNil())
Expect(dep.Metadata).ToNot(BeNil())

podSpec := dep.Spec.Template.Spec.Kubernetes.Pods
Expect(podSpec.EnvVars).To(HaveLen(2))
Expect(podSpec.EnvVars[1].ValueFrom.SecretKeyRef).ToNot(BeNil())
Expect(podSpec.EnvVars[1].ValueFrom.SecretKeyRef.Name).To(Equal("some-secret"))
Expect(podSpec.EnvVars[1].ValueFrom.SecretKeyRef.Key).To(Equal("api-key"))
Expect(podSpec.EnvVars[1].ValueFrom.SecretKeyRef.Optional).ToNot(BeNil())
Expect(*podSpec.EnvVars[1].ValueFrom.SecretKeyRef.Optional).To(BeTrue())

Expect(dep.Status).ToNot(BeNil())
Expect(dep.Status.State).To(Equal(string(v1beta2.RunningState)))
Expect(dep.Status.Running).ToNot(BeNil())
Expand Down

0 comments on commit 890a986

Please sign in to comment.