Skip to content

Commit

Permalink
fix: helm templating (#295)
Browse files Browse the repository at this point in the history
* fix helm templating

* fix linter

* fix helm test

* change test values.yaml file

* try w/ basic values.yaml

---------

Co-authored-by: michaeljguarino <[email protected]>
  • Loading branch information
zreigz and michaeljguarino authored Oct 4, 2024
1 parent e5b2955 commit e6b5b79
Show file tree
Hide file tree
Showing 8 changed files with 1,319 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/cache/discovery_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"time"

cmap "github.com/orcaman/concurrent-map/v2"
"github.com/pluralsh/deployment-operator/internal/helpers"
"github.com/pluralsh/deployment-operator/internal/metrics"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/klog/v2"

"github.com/pluralsh/deployment-operator/internal/helpers"
"github.com/pluralsh/deployment-operator/internal/metrics"
)

var (
Expand Down Expand Up @@ -61,6 +60,7 @@ func updateDiscoveryCache(discoveryClient *discovery.DiscoveryClient) error {
}

discoveryCache.Set(fmt.Sprintf("%s/%s", gv.String(), resource.Kind), true)
discoveryCache.Set(gv.String(), true)
}
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/manifests/template/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
)

var _ = Describe("Helm template", func() {

dir := filepath.Join("..", "..", "..", "charts", "deployment-operator")
svc := &console.GetServiceDeploymentForAgent_ServiceDeployment{
Namespace: "default",
Name: "test",
Expand Down Expand Up @@ -61,11 +59,14 @@ var _ = Describe("Helm template", func() {
})

Context("Render helm template", func() {
It("should successfully render the helm template", func() {
It("should successfully render Capabilities.APIVersions.Has", func() {
dir := filepath.Join("..", "..", "..", "test", "helm", "yet-another-cloudwatch-exporter")

resp, err := NewHelm(dir).Render(svc, utilFactory)
Expect(err).NotTo(HaveOccurred())
Expect(len(resp)).To(Equal(14))
Expect(len(resp)).To(Equal(1))
})

})

})
16 changes: 14 additions & 2 deletions pkg/manifests/template/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ limitations under the License.
package template

import (
"context"
"fmt"
"path/filepath"
"runtime"
"testing"

cmdtesting "k8s.io/kubectl/pkg/cmd/testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pluralsh/deployment-operator/pkg/cache"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes/scheme"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
Expand All @@ -39,6 +41,7 @@ import (
var k8sClient client.Client
var utilFactory util.Factory
var testEnv *envtest.Environment
var discoveryClient *discovery.DiscoveryClient

func TestControllers(t *testing.T) {
RegisterFailHandler(Fail)
Expand All @@ -50,6 +53,8 @@ var _ = BeforeSuite(func() {

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "test", "crd")},
ErrorIfCRDPathMissing: true,
BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s",
fmt.Sprintf("1.28.3-%s-%s", runtime.GOOS, runtime.GOARCH)),
}
Expand All @@ -61,6 +66,13 @@ var _ = BeforeSuite(func() {
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())

discoveryClient, err = discovery.NewDiscoveryClientForConfig(cfg)
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())

cache.RunDiscoveryCacheInBackgroundOrDie(context.Background(), discoveryClient)

utilFactory = cmdtesting.NewTestFactory()
})

Expand Down
Loading

0 comments on commit e6b5b79

Please sign in to comment.