Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit b3bd748

Browse files
update testcase logic; temporary commit - needs cleanup
1 parent 4452863 commit b3bd748

File tree

7 files changed

+422
-36
lines changed

7 files changed

+422
-36
lines changed

tests/e2e/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/twmb/franz-go v1.13.5
1515
k8s.io/apiextensions-apiserver v0.26.4
1616
k8s.io/apimachinery v0.26.4
17+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
1718
sigs.k8s.io/yaml v1.3.0
1819
)
1920

@@ -125,7 +126,6 @@ require (
125126
k8s.io/client-go v0.26.4 // indirect
126127
k8s.io/klog/v2 v2.80.1 // indirect
127128
k8s.io/kube-openapi v0.0.0-20221207184640-f3cff1453715 // indirect
128-
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
129129
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
130130
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
131131
)

tests/e2e/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=
845845
k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
846846
k8s.io/kube-openapi v0.0.0-20221207184640-f3cff1453715 h1:tBEbstoM+K0FiBV5KGAKQ0kuvf54v/hwpldiJt69w1s=
847847
k8s.io/kube-openapi v0.0.0-20221207184640-f3cff1453715/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
848-
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 h1:KTgPnR10d5zhztWptI952TNtt/4u5h3IzDXkdIMuo2Y=
849-
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
848+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
849+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
850850
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
851851
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
852852
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

tests/e2e/k8s.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func applyK8sResourceManifestFromString(kubectlOptions k8s.KubectlOptions, manif
8181

8282
// applyK8sResourceFromTemplate generates manifest from the specified go-template based on values
8383
// and applies the specified manifest to the provided kubectl context and namespace.
84-
func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFile string, values map[string]interface{}, extraArgs ...string) error {
84+
func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFile string, values map[string]any, extraArgs ...string) error {
8585
By(fmt.Sprintf("Generating k8s manifest from template %s", templateFile))
8686
var manifest bytes.Buffer
8787
rawTemplate, err := os.ReadFile(templateFile)
@@ -96,6 +96,24 @@ func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFil
9696
return applyK8sResourceManifestFromString(kubectlOptions, manifest.String(), extraArgs...)
9797
}
9898

99+
// applyK8sResourceFromTemplate generates manifest from the specified go-template based on values
100+
// and applies the specified manifest to the provided kubectl context and namespace.
101+
func applyK8sResourceFromTemplate_2(kubectlOptions k8s.KubectlOptions, templateFile string, values any, extraArgs ...string) error {
102+
By(fmt.Sprintf("Generating k8s manifest from template %s", templateFile))
103+
var manifest bytes.Buffer
104+
rawTemplate, err := os.ReadFile(templateFile)
105+
if err != nil {
106+
return err
107+
}
108+
t := template.Must(template.New("template").Funcs(sprig.TxtFuncMap()).Parse(string(rawTemplate)))
109+
err = t.Execute(&manifest, values)
110+
if err != nil {
111+
return err
112+
}
113+
fmt.Printf("###\nManifest is :\n%s\n###\n", manifest.String())
114+
return applyK8sResourceManifestFromString(kubectlOptions, manifest.String(), extraArgs...)
115+
}
116+
99117
// isExistingK8SResource queries a Resource by it's kind, namespace and name and
100118
// returns true if it's found, false otherwise
101119
func isExistingK8SResource(

tests/e2e/kafka.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/gruntwork-io/terratest/modules/k8s"
2222
. "github.com/onsi/ginkgo/v2"
2323
. "github.com/onsi/gomega"
24+
"k8s.io/utils/ptr"
2425
)
2526

2627
// requireDeleteKafkaTopic deletes kafkaTopic resource.
@@ -34,14 +35,29 @@ func requireDeleteKafkaTopic(kubectlOptions k8s.KubectlOptions, topicName string
3435
// requireDeployingKafkaTopic deploys a kafkaTopic resource from a template
3536
func requireDeployingKafkaTopic(kubectlOptions k8s.KubectlOptions, topicName string) {
3637
It("Deploying KafkaTopic CR", func() {
37-
err := applyK8sResourceFromTemplate(kubectlOptions,
38-
kafkaTopicTemplate,
39-
map[string]interface{}{
40-
"Name": topicName,
41-
"TopicName": topicName,
42-
"Namespace": kubectlOptions.Namespace,
38+
// err := applyK8sResourceFromTemplate(kubectlOptions,
39+
// kafkaTopicTemplate,
40+
// map[string]interface{}{
41+
// "Name": topicName,
42+
// "TopicName": topicName,
43+
// "Namespace": kubectlOptions.Namespace,
44+
// },
45+
// )
46+
values := kafkaTopicTemplateData{
47+
Annotations: []string{"managedBy: koperator"},
48+
ClusterRef: kafkaTopicClusterRef{
49+
Name: kafkaClusterName,
50+
Namespace: kubectlOptions.Namespace,
4351
},
44-
)
52+
Name: topicName,
53+
Namespace: kubectlOptions.Namespace,
54+
Partitions: ptr.To(int32(2)),
55+
ReplicationFactor: ptr.To(int32(2)),
56+
TopicName: topicName,
57+
}
58+
59+
err := applyK8sResourceFromTemplate_2(kubectlOptions, kafkaTopicTemplate, values)
60+
4561
Expect(err).ShouldNot(HaveOccurred())
4662

4763
err = waitK8sResourceCondition(kubectlOptions, kafkaTopicKind,
@@ -82,3 +98,23 @@ func requireDeployingKafkaUser(kubectlOptions k8s.KubectlOptions, userName strin
8298
}, defaultUserCreationWaitTime, 3*time.Second).Should(Equal(true))
8399
})
84100
}
101+
102+
// kafkaTopicTemplateData is a struct that holds the relevant information and structure
103+
// to fill out the template used to generate KafkaTopics.
104+
// TODO: long term we should use the structs in the api module instead of these local structs.
105+
type kafkaTopicTemplateData struct {
106+
Annotations []string
107+
ClusterRef kafkaTopicClusterRef
108+
Name string
109+
Namespace string
110+
Partitions *int32
111+
ReplicationFactor *int32
112+
TopicName string
113+
}
114+
115+
// kafkaTopicClusterRef holds the information relevant to identifying a KafkaCluster within a KafkaTopic CR.
116+
// TODO: Long term, we should use the structs in the api module instead of these local structs.
117+
type kafkaTopicClusterRef struct {
118+
Name string
119+
Namespace string
120+
}

0 commit comments

Comments
 (0)