@@ -105,6 +105,66 @@ func Test_releaseToFiles(t *testing.T) {
105105 }
106106}
107107
108+ func Test_filterV1Beta3 (t * testing.T ) {
109+ tests := []struct {
110+ name string
111+ filename string
112+ content []byte
113+ wantOk bool
114+ wantContent []byte
115+ }{
116+ {
117+ name : "not a v1beta3 doc" ,
118+ filename : "manifests/deployment.yaml" ,
119+ content : []byte ("a: b" ),
120+ wantOk : true ,
121+ wantContent : []byte ("a: b" ),
122+ },
123+ {
124+ name : "v1beta3 doc, any kind, is dropped entirely" ,
125+ filename : "manifests/preflight.yaml" ,
126+ content : []byte ("apiVersion: troubleshoot.sh/v1beta3\n kind: Preflight\n " ),
127+ wantOk : false ,
128+ wantContent : nil ,
129+ },
130+ {
131+ name : "only the v1beta3 doc is stripped from a multi-doc file mixing v1beta2 and v1beta3" ,
132+ filename : "manifests/preflight.yaml" ,
133+ content : []byte (
134+ "apiVersion: troubleshoot.sh/v1beta2\n kind: Preflight\n metadata:\n name: v2\n " +
135+ "\n ---\n " +
136+ "apiVersion: troubleshoot.sh/v1beta3\n kind: Preflight\n metadata:\n name: v3\n " ,
137+ ),
138+ wantOk : true ,
139+ wantContent : []byte ("apiVersion: troubleshoot.sh/v1beta2\n kind: Preflight\n metadata:\n name: v2\n " ),
140+ },
141+ {
142+ name : "v1beta3 doc is dropped even when a template breaks yaml parsing of the rest of the doc" ,
143+ filename : "manifests/preflight.yaml" ,
144+ content : []byte (
145+ "apiVersion: troubleshoot.sh/v1beta3\n kind: Preflight\n metadata:\n name: vendorflow\n spec:\n " +
146+ " collectors:\n {{- if eq .Chart.Name \" vendorflow\" }}\n - clusterInfo: {}\n {{- end }}\n " ,
147+ ),
148+ wantOk : false ,
149+ wantContent : nil ,
150+ },
151+ {
152+ name : "packaged helm chart archives are left untouched" ,
153+ filename : "manifests/vendorflow-0.1.0.tgz" ,
154+ content : []byte ("apiVersion: troubleshoot.sh/v1beta3\n kind: Preflight\n " ), // not real tgz content, but proves content is never inspected
155+ wantOk : true ,
156+ wantContent : []byte ("apiVersion: troubleshoot.sh/v1beta3\n kind: Preflight\n " ),
157+ },
158+ }
159+ for _ , tt := range tests {
160+ t .Run (tt .name , func (t * testing.T ) {
161+ content , ok := filterV1Beta3 (tt .filename , tt .content )
162+ require .Equal (t , tt .wantOk , ok )
163+ require .Equal (t , tt .wantContent , content )
164+ })
165+ }
166+ }
167+
108168func Test_createConfigValues (t * testing.T ) {
109169 applicationName := "Test App"
110170 appInfo := & template.ApplicationInfo {Slug : "app-slug" }
@@ -735,6 +795,42 @@ spec:
735795 }
736796 })
737797
798+ t .Run ("drops v1beta3 docs from the release's manifests" , func (t * testing.T ) {
799+ v1beta3Files := map [string ][]byte {
800+ "manifests/app.yaml" : testFiles ["manifests/app.yaml" ],
801+ "manifests/preflight.yaml" : []byte ("apiVersion: troubleshoot.sh/v1beta3\n kind: Preflight\n " ),
802+ }
803+
804+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
805+ var buf bytes.Buffer
806+ gzipWriter := gzip .NewWriter (& buf )
807+ tarWriter := tar .NewWriter (gzipWriter )
808+
809+ for name , content := range v1beta3Files {
810+ header := & tar.Header {Name : name , Mode : 0600 , Size : int64 (len (content ))}
811+ require .NoError (t , tarWriter .WriteHeader (header ))
812+ _ , err := tarWriter .Write (content )
813+ require .NoError (t , err )
814+ }
815+
816+ require .NoError (t , tarWriter .Close ())
817+ require .NoError (t , gzipWriter .Close ())
818+
819+ w .WriteHeader (http .StatusOK )
820+ w .Write (buf .Bytes ())
821+ }))
822+ defer server .Close ()
823+
824+ license .V1 .Spec .Endpoint = server .URL
825+
826+ release , err := downloadReplicatedApp (upstr , license , cursor , nil , "" )
827+ require .NoError (t , err )
828+
829+ _ , ok := release .Manifests ["manifests/preflight.yaml" ]
830+ require .False (t , ok , "expected the v1beta3 preflight to be dropped from the release's manifests" )
831+ require .Equal (t , testFiles ["manifests/app.yaml" ], release .Manifests ["manifests/app.yaml" ])
832+ })
833+
738834 // Test error cases
739835 t .Run ("HTTP error" , func (t * testing.T ) {
740836 errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
0 commit comments