@@ -65,14 +65,9 @@ func applyK8sResourceManifest(kubectlOptions k8s.KubectlOptions, manifestPath st
6565// applyK8sResourceManifestFromString applies the specified manifest in string format to the provided
6666// kubectl context and namespace.
6767func applyK8sResourceManifestFromString (kubectlOptions k8s.KubectlOptions , manifest string , extraArgs ... string ) error {
68- // Replicating terratest's k8s.KubectlApplyFromStringE but with the possibility of a variadic argument that allows options like --dry-run
69- //
70- // TODO: look for a different implementation for temp files because terratest's version uses the composite test name to generate
71- // the temp file name which, in our case, includes all the descriptive Ginkgo statements (which are by design quite verbose).
72- // That can lead to erroring out on temp file creation based on the file name being too long.
73- tmpfile , err := k8s .StoreConfigToTempFileE (GinkgoT (), manifest )
68+ tmpfile , err := createTempFileFromBytes ([]byte (manifest ), "" , "" , 0 )
7469 if err != nil {
75- return err
70+ return fmt . Errorf ( "storing provided manifest data into temp file failed: %w" , err )
7671 }
7772 defer os .Remove (tmpfile )
7873
@@ -81,7 +76,7 @@ func applyK8sResourceManifestFromString(kubectlOptions k8s.KubectlOptions, manif
8176
8277// applyK8sResourceFromTemplate generates manifest from the specified go-template based on values
8378// and applies the specified manifest to the provided kubectl context and namespace.
84- func applyK8sResourceFromTemplate (kubectlOptions k8s.KubectlOptions , templateFile string , values map [ string ] any , extraArgs ... string ) error {
79+ func applyK8sResourceFromTemplate (kubectlOptions k8s.KubectlOptions , templateFile string , values any , extraArgs ... string ) error {
8580 By (fmt .Sprintf ("Generating k8s manifest from template %s" , templateFile ))
8681 var manifest bytes.Buffer
8782 rawTemplate , err := os .ReadFile (templateFile )
@@ -93,24 +88,7 @@ func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFil
9388 if err != nil {
9489 return err
9590 }
96- return applyK8sResourceManifestFromString (kubectlOptions , manifest .String (), extraArgs ... )
97- }
9891
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 ("###\n Manifest is :\n %s\n ###\n " , manifest .String ())
11492 return applyK8sResourceManifestFromString (kubectlOptions , manifest .String (), extraArgs ... )
11593}
11694
0 commit comments