Skip to content

Commit

Permalink
Begin generating port helm values & handling helm updates (#106)
Browse files Browse the repository at this point in the history
* Add generating of port to helm values

Signed-off-by: Tyler Auerbeck <[email protected]>

* Take action on helm updates

Signed-off-by: Tyler Auerbeck <[email protected]>

* Fix port logging

Signed-off-by: Tyler Auerbeck <[email protected]>

---------

Signed-off-by: Tyler Auerbeck <[email protected]>
Co-authored-by: Tyler Auerbeck <[email protected]>
  • Loading branch information
tylerauerbeck and tylerauerbeck authored Jun 20, 2023
1 parent 73cb93a commit 7733431
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 47 deletions.
6 changes: 6 additions & 0 deletions cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func init() {
processCmd.PersistentFlags().String("kube-config-path", "", "path to a valid kubeconfig file")
viperx.MustBindFlag(viper.GetViper(), "kube-config-path", processCmd.PersistentFlags().Lookup("kube-config-path"))

processCmd.PersistentFlags().String("helm-containerport-key", "containerPorts", "key to use for injecting port values for deployment into chart")
viperx.MustBindFlag(viper.GetViper(), "helm-containerport-key", processCmd.PersistentFlags().Lookup("helm-containerport-key"))

processCmd.PersistentFlags().String("helm-serviceport-key", "service.ports", "key to use for injecting port values for service into chart")
viperx.MustBindFlag(viper.GetViper(), "helm-serviceport-key", processCmd.PersistentFlags().Lookup("helm-serviceport-key"))

rootCmd.AddCommand(processCmd)
}

Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/stretchr/testify v1.8.4
go.infratographer.com/x v0.3.1-0.20230605180922-67c1a1e705ac
go.uber.org/zap v1.24.0
helm.sh/helm/v3 v3.11.3
helm.sh/helm/v3 v3.12.0
k8s.io/apimachinery v0.27.1
k8s.io/cli-runtime v0.27.1
k8s.io/client-go v0.27.1
Expand Down Expand Up @@ -142,12 +142,12 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.27.1
k8s.io/apiextensions-apiserver v0.26.1 // indirect
k8s.io/apiserver v0.26.2 // indirect
k8s.io/component-base v0.26.2 // indirect
k8s.io/apiextensions-apiserver v0.27.1 // indirect
k8s.io/apiserver v0.27.1 // indirect
k8s.io/component-base v0.27.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect
k8s.io/kubectl v0.26.0 // indirect
k8s.io/kubectl v0.27.1 // indirect
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
oras.land/oras-go v1.2.2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
26 changes: 13 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
github.com/foxcpp/go-mockdns v1.0.0 h1:7jBqxd3WDWwi/6WhDvacvH1XsN3rOLXyHM1uhvIx6FI=
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -474,6 +475,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.25 h1:dFwPR6SfLtrSwgDcIq2bcU/gVutB4sNApq2HBdqcakg=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down Expand Up @@ -690,8 +692,6 @@ go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230524022050-2d83ce4fef64 h1:GoY2TzlKH/ZXmkqX7cLx9St+cuqg09pggcOvDXEFwME=
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230524022050-2d83ce4fef64/go.mod h1:4Di7Vzg55I2/RH9P4B4Y63Muuxl0CNTsiCrwIu3UzCs=
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230612145135-7bf6c8074a9e h1:1tpVzkkoP+HKC6AjLKWvm6Z25rYqeIN/Lh2dorQNWx0=
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230612145135-7bf6c8074a9e/go.mod h1:mrwcbc0ljw0up+sX+umoa1FydiqSeMiynlR6QIO9dqU=
go.infratographer.com/x v0.3.1-0.20230605180922-67c1a1e705ac h1:5PFHsIXYJqF6ALLA39JicYzkSeLOgeF1zg3Vr68GZm8=
Expand Down Expand Up @@ -1180,9 +1180,9 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
helm.sh/helm/v3 v3.11.3 h1:n1X5yaQTP5DYywlBOZMl2gX398Gp6YwFp/IAVj6+5D4=
helm.sh/helm/v3 v3.11.3/go.mod h1:S+sOdQc3BLvt09a9rSlKKVs9x0N/yx+No0y3qFw+FQ8=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
helm.sh/helm/v3 v3.12.0 h1:rOq2TPVzg5jt4q5ermAZGZFxNW2uQhKjRhBneAutMEM=
helm.sh/helm/v3 v3.12.0/go.mod h1:8K/469yxjUMu6BaD2EagCitkPjELUL/l2AgCO142G94=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand All @@ -1192,24 +1192,24 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.27.1 h1:Z6zUGQ1Vd10tJ+gHcNNNgkV5emCyW+v2XTmn+CLjSd0=
k8s.io/api v0.27.1/go.mod h1:z5g/BpAiD+f6AArpqNjkY+cji8ueZDU/WV1jcj5Jk4E=
k8s.io/apiextensions-apiserver v0.26.1 h1:cB8h1SRk6e/+i3NOrQgSFij1B2S0Y0wDoNl66bn8RMI=
k8s.io/apiextensions-apiserver v0.26.1/go.mod h1:AptjOSXDGuE0JICx/Em15PaoO7buLwTs0dGleIHixSM=
k8s.io/apiextensions-apiserver v0.27.1 h1:Hp7B3KxKHBZ/FxmVFVpaDiXI6CCSr49P1OJjxKO6o4g=
k8s.io/apiextensions-apiserver v0.27.1/go.mod h1:8jEvRDtKjVtWmdkhOqE84EcNWJt/uwF8PC4627UZghY=
k8s.io/apimachinery v0.27.1 h1:EGuZiLI95UQQcClhanryclaQE6xjg1Bts6/L3cD7zyc=
k8s.io/apimachinery v0.27.1/go.mod h1:5ikh59fK3AJ287GUvpUsryoMFtH9zj/ARfWCo3AyXTM=
k8s.io/apiserver v0.26.2 h1:Pk8lmX4G14hYqJd1poHGC08G03nIHVqdJMR0SD3IH3o=
k8s.io/apiserver v0.26.2/go.mod h1:GHcozwXgXsPuOJ28EnQ/jXEM9QeG6HT22YxSNmpYNh8=
k8s.io/apiserver v0.27.1 h1:phY+BtXjjzd+ta3a4kYbomC81azQSLa1K8jo9RBw7Lg=
k8s.io/apiserver v0.27.1/go.mod h1:UGrOjLY2KsieA9Fw6lLiTObxTb8Z1xEba4uqSuMY0WU=
k8s.io/cli-runtime v0.27.1 h1:MMzp5Q/Xmr5L1Lrowuc+Y/r95XINC6c6/fE3aN7JDRM=
k8s.io/cli-runtime v0.27.1/go.mod h1:tEbTB1XP/nTH3wujsi52bw91gWpErtWiS15R6CwYsAI=
k8s.io/client-go v0.27.1 h1:oXsfhW/qncM1wDmWBIuDzRHNS2tLhK3BZv512Nc59W8=
k8s.io/client-go v0.27.1/go.mod h1:f8LHMUkVb3b9N8bWturc+EDtVVVwZ7ueTVquFAJb2vA=
k8s.io/component-base v0.26.2 h1:IfWgCGUDzrD6wLLgXEstJKYZKAFS2kO+rBRi0p3LqcI=
k8s.io/component-base v0.26.2/go.mod h1:DxbuIe9M3IZPRxPIzhch2m1eT7uFrSBJUBuVCQEBivs=
k8s.io/component-base v0.27.1 h1:kEB8p8lzi4gCs5f2SPU242vOumHJ6EOsOnDM3tTuDTM=
k8s.io/component-base v0.27.1/go.mod h1:UGEd8+gxE4YWoigz5/lb3af3Q24w98pDseXcXZjw+E0=
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a h1:gmovKNur38vgoWfGtP5QOGNOA7ki4n6qNYoFAgMlNvg=
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY=
k8s.io/kubectl v0.26.0 h1:xmrzoKR9CyNdzxBmXV7jW9Ln8WMrwRK6hGbbf69o4T0=
k8s.io/kubectl v0.26.0/go.mod h1:eInP0b+U9XUJWSYeU9XZnTA+cVYuWyl3iYPGtru0qhQ=
k8s.io/kubectl v0.27.1 h1:9T5c5KdpburYiW8XKQSH0Uly1kMNE90aGSnbYUZNdcA=
k8s.io/kubectl v0.27.1/go.mod h1:QsAkSmrRsKTPlAFzF8kODGDl4p35BIwQnc9XFhkcsy8=
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk=
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
oras.land/oras-go v1.2.2 h1:0E9tOHUfrNH7TCDk5KU0jVBEzCqbfdyuVfGmJ7ZeRPE=
Expand Down
34 changes: 34 additions & 0 deletions internal/srv/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,40 @@ func (s *Server) newDeployment(lb *loadBalancer) error {
return nil
}

func (s *Server) updateDeployment(lb *loadBalancer) error {
hash := hashLBName(lb.loadBalancerID.String())

releaseName := fmt.Sprintf("lb-%s", hash)
if !checkNameLength(releaseName, helmReleaseLength) {
releaseName = releaseName[0:helmReleaseLength]
}

values, err := s.newHelmValues(lb)
if err != nil {
s.Logger.Errorw("unable to prepare chart values", "error", err)
return err
}

client, err := s.newHelmClient(hash)
if err != nil {
s.Logger.Errorw("unable to initialize helm client", "error", err)
return err
}

hc := action.NewUpgrade(client)
hc.Namespace = hash
_, err = hc.Run(releaseName, s.Chart, values)

if err != nil {
s.Logger.Errorw("unable to upgrade loadbalancer", "error", err, "namespace", hash, "releaseName", releaseName)
return err
}

s.Logger.Infow("loadbalancer upgraded successfully", "namespace", hash, "releaseName", releaseName)

return nil
}

func (s *Server) removeDeployment(lb *loadBalancer) error {
hash := hashLBName(lb.loadBalancerID.String())

Expand Down
4 changes: 4 additions & 0 deletions internal/srv/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ func (s *Server) processLoadBalancerChangeDelete(lb *loadBalancer) error {
}

func (s *Server) processLoadBalancerChangeUpdate(lb *loadBalancer) error {
if err := s.updateDeployment(lb); err != nil {
return err
}

return nil
}
35 changes: 31 additions & 4 deletions internal/srv/changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,39 @@ func (suite srvTestSuite) TestProcessLoadBalancerDelete() { //nolint:govet
}

func (suite srvTestSuite) TestProcessLoadBalancerUpdate() { //nolint:govet
srv := &Server{}
lb := &loadBalancer{
loadBalancerID: gidx.MustNewID("loadbal"),
dir, cp, ch, pwd := utils.CreateWorkspace("test-delete-lb")
defer os.RemoveAll(dir)

eSrv, err := echox.NewServer(zap.NewNop(), echox.Config{}, nil)

require.NoError(suite.T(), err, "unexpected error creating new server")

api := mock.DummyAPI(dummyLB.String())
api.Start()

defer api.Close()

srv := Server{
APIClient: lbapi.NewClient(api.URL),
KubeClient: suite.Kubeenv.Config,
Echo: eSrv,
Context: context.TODO(),
Logger: zap.NewNop().Sugar(),
Chart: ch,
Debug: false,
Topics: []string{"foo", "bar"},
ChartPath: cp,
ValuesPath: pwd + "/../../hack/ci/values.yaml",
}

id := gidx.MustNewID("loadbal")
lb, _ := srv.newLoadBalancer(id, nil)

err = srv.processLoadBalancerChangeCreate(lb)

assert.NoError(suite.T(), err)

u := srv.processLoadBalancerChangeUpdate(lb)

assert.Nil(suite.T(), u)
assert.NoError(suite.T(), u)
}
41 changes: 33 additions & 8 deletions internal/srv/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package srv

import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"

Expand All @@ -21,17 +22,41 @@ const (
managedHelmKeyPrefix = "operator.managed"
)

func (v helmvalues) generateLBHelmVals(lb *loadBalancer) {
func (v helmvalues) generateLBHelmVals(lb *loadBalancer, s *Server) {
// add loadbalancer id values
v.addValue("loadBalancerID", lb.loadBalancerID.String())
v.addValue("loadBalancerIDEnc", hex.EncodeToString([]byte(lb.loadBalancerID.String())))
}
v.StringValues = append(v.StringValues, fmt.Sprintf("%s=%s", managedHelmKeyPrefix+".loadBalancerID", lb.loadBalancerID.String()))
v.StringValues = append(v.StringValues, fmt.Sprintf("%s=%s", managedHelmKeyPrefix+".loadBalancerIDEnc", hex.EncodeToString([]byte(lb.loadBalancerID.String()))))

// add port values
var cport, sport []interface{}

for _, port := range lb.lbData.LoadBalancer.Ports.Edges {
cport = append(cport, map[string]interface{}{"name": port.Node.Name, "containerPort": port.Node.Number})
sport = append(sport, map[string]interface{}{"name": port.Node.Name, "port": port.Node.Number})
}

func (v helmvalues) addValue(key string, value interface{}) {
val := fmt.Sprintf("%s.%s=%s", managedHelmKeyPrefix, key, value)
v.StringValues = append(v.StringValues, val)
if cport != nil {
if cports, err := json.Marshal(cport); err != nil {
s.Logger.Debugw("unable to marshal container ports", "error", err, "loadbalancer", lb.loadBalancerID.String())
} else {
v.JSONValues = append(v.JSONValues, fmt.Sprintf("%s=%s", s.ContainerPortKey, string(cports)))
}
}

if sport != nil {
if sports, err := json.Marshal(sport); err != nil {
s.Logger.Debugw("unable to marshal service ports", "error", err, "loadbalancer", lb.loadBalancerID.String())
} else {
v.JSONValues = append(v.JSONValues, fmt.Sprintf("%s=%s", s.ServicePortKey, string(sports)))
}
}
}

// func (v helmvalues) addValue(key string, value interface{}) {
// val := fmt.Sprintf("%s.%s=%s", managedHelmKeyPrefix, key, value)
// v.StringValues = append(v.StringValues, val)
// }

func (s *Server) newHelmClient(namespace string) (*action.Configuration, error) {
config := &action.Configuration{}
cliopt := genericclioptions.NewConfigFlags(false)
Expand All @@ -56,7 +81,7 @@ func (s *Server) newHelmValues(lb *loadBalancer) (map[string]interface{}, error)
ValueFiles: []string{s.ValuesPath},
}}

opts.generateLBHelmVals(lb)
opts.generateLBHelmVals(lb, s)

values, err := opts.MergeValues(provider)
if err != nil {
Expand Down
58 changes: 43 additions & 15 deletions internal/srv/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.infratographer.com/loadbalancer-manager-haproxy/pkg/lbapi"
"go.infratographer.com/loadbalanceroperator/internal/utils/mock"
"go.infratographer.com/x/gidx"
"go.uber.org/zap"

Expand All @@ -20,35 +22,48 @@ var (
)

func (suite *srvTestSuite) TestGenerateLBHelmVals() {
lb := &loadBalancer{
loadBalancerID: gidx.MustNewID("loadbal"),
id := gidx.MustNewID("loadbal")
api := mock.DummyAPI(id.String())
api.Start()

defer api.Close()

s := &Server{
Context: context.TODO(),
APIClient: lbapi.NewClient(api.URL),
ContainerPortKey: "containerPorts",
ServicePortKey: "service.ports",
Logger: zap.NewNop().Sugar(),
}

lb, _ := s.newLoadBalancer(id, nil)

hash := hex.EncodeToString([]byte(lb.loadBalancerID.String()))

opts := helmvalues{&values.Options{}}

assert.Nil(suite.T(), opts.StringValues)

opts.generateLBHelmVals(lb)
opts.generateLBHelmVals(lb, s)

assert.NotNil(suite.T(), opts.StringValues)
assert.Len(suite.T(), opts.StringValues, 2)
assert.Contains(suite.T(), opts.StringValues, managedHelmKeyPrefix+".loadBalancerID="+lb.loadBalancerID.String())
assert.Contains(suite.T(), opts.StringValues, managedHelmKeyPrefix+".loadBalancerIDEnc="+hash)

assert.NotNil(suite.T(), opts.JSONValues)
}

func (suite *srvTestSuite) TestAddValue() { //nolint:stylecheck
opts := helmvalues{&values.Options{}}
// func (suite *srvTestSuite) TestAddValue() { //nolint:stylecheck
// opts := helmvalues{&values.Options{}}

assert.Nil(suite.T(), opts.StringValues)
// assert.Nil(suite.T(), opts.StringValues)

opts.addValue(dummyKey, dummyVal)
// opts.addValue(dummyKey, dummyVal)

assert.NotNil(suite.T(), opts.StringValues)
assert.Len(suite.T(), opts.StringValues, 1)
assert.Contains(suite.T(), opts.StringValues, managedHelmKeyPrefix+"."+dummyKey+"="+dummyVal)
}
// assert.NotNil(suite.T(), opts.StringValues)
// assert.Len(suite.T(), opts.StringValues, 1)
// assert.Contains(suite.T(), opts.StringValues, managedHelmKeyPrefix+"."+dummyKey+"="+dummyVal)
// }

func (suite *srvTestSuite) TestNewHelmValues() {
type testCase struct {
Expand All @@ -63,6 +78,12 @@ func (suite *srvTestSuite) TestNewHelmValues() {
suite.T().Fatal(err)
}

id := gidx.MustNewID("loadbal")
api := mock.DummyAPI(id.String())
api.Start()

defer api.Close()

testCases := []testCase{
{
name: "valid values path",
Expand Down Expand Up @@ -93,10 +114,17 @@ func (suite *srvTestSuite) TestNewHelmValues() {
for _, tcase := range testCases {
suite.T().Run(tcase.name, func(t *testing.T) {
srv := Server{
Logger: zap.NewNop().Sugar(),
ValuesPath: tcase.valuesPath,
Context: context.TODO(),
APIClient: lbapi.NewClient(api.URL),
Logger: zap.NewNop().Sugar(),
ValuesPath: tcase.valuesPath,
ContainerPortKey: "containerPorts",
ServicePortKey: "service.ports",
}
values, err := srv.newHelmValues(tcase.lb)

lb, _ := srv.newLoadBalancer(tcase.lb.loadBalancerID, nil)

values, err := srv.newHelmValues(lb)
if tcase.expectError {
assert.NotNil(t, err)
} else {
Expand Down
2 changes: 2 additions & 0 deletions internal/srv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Server struct {
ChartPath string
ValuesPath string
Locations []string
ServicePortKey string
ContainerPortKey string
}

// Run will start the server queue connections and healthcheck endpoints
Expand Down
Loading

0 comments on commit 7733431

Please sign in to comment.