@@ -1798,12 +1798,13 @@ func TestResolveChartJobs_ExcludeExtras(t *testing.T) {
17981798 tests := []struct {
17991799 name string
18001800 cli bool
1801+ cliChanged bool
18011802 annotation string
18021803 perChart bool
18031804 want bool
18041805 }{
18051806 {name : "nothing set" , want : false },
1806- {name : "CLI flag alone" , cli : true , want : true },
1807+ {name : "CLI flag alone" , cli : true , cliChanged : true , want : true },
18071808 {name : "annotation alone" , annotation : "true" , want : true },
18081809 {name : "per-chart alone" , perChart : true , want : true },
18091810 {
@@ -1816,26 +1817,37 @@ func TestResolveChartJobs_ExcludeExtras(t *testing.T) {
18161817 // --exclude-extras back off; both are one-way switches.
18171818 name : "CLI flag survives an annotation that is not true" ,
18181819 cli : true ,
1820+ cliChanged : true ,
18191821 annotation : "false" ,
18201822 want : true ,
18211823 },
18221824 {
1823- name : "CLI flag survives a false per-chart field" ,
1824- cli : true ,
1825- perChart : false ,
1826- want : true ,
1825+ name : "CLI flag survives a false per-chart field" ,
1826+ cli : true ,
1827+ cliChanged : true ,
1828+ perChart : false ,
1829+ want : true ,
18271830 },
18281831 {
18291832 name : "annotation survives a false per-chart field" ,
18301833 annotation : "true" ,
18311834 perChart : false ,
18321835 want : true ,
18331836 },
1837+ {
1838+ // An explicit CLI --exclude-extras=false wins outright over an
1839+ // annotation/per-chart true.
1840+ name : "explicit CLI false overrides annotation and per-chart" ,
1841+ cliChanged : true ,
1842+ annotation : "true" ,
1843+ perChart : true ,
1844+ want : false ,
1845+ },
18341846 }
18351847
18361848 for _ , tc := range tests {
18371849 t .Run (tc .name , func (t * testing.T ) {
1838- o := & flags.SyncOpts {ExcludeExtras : tc .cli }
1850+ o := & flags.SyncOpts {ExcludeExtras : tc .cli , ExcludeExtrasChanged : tc . cliChanged }
18391851 a := map [string ]string {}
18401852 if tc .annotation != "" {
18411853 a [consts .ImageAnnotationExcludeExtras ] = tc .annotation
@@ -1877,10 +1889,16 @@ func TestResolveChartJobs_Platform(t *testing.T) {
18771889 want : "linux/amd64" ,
18781890 },
18791891 {
1880- name : "per-chart wins over both " ,
1892+ name : "CLI flag wins over annotation and per-chart " ,
18811893 cli : "linux/amd64" ,
18821894 annotation : "linux/arm64" ,
18831895 perChart : "linux/s390x" ,
1896+ want : "linux/amd64" ,
1897+ },
1898+ {
1899+ name : "per-chart wins over annotation when CLI flag unset" ,
1900+ annotation : "linux/arm64" ,
1901+ perChart : "linux/s390x" ,
18841902 want : "linux/s390x" ,
18851903 },
18861904 {
@@ -2155,7 +2173,6 @@ func TestResolveChartJobs_NoCharts(t *testing.T) {
21552173// TestResolveChartJobs_CredentialFields pins that every TLS/verification
21562174// field on v1.Chart reaches the job's ChartOpts unchanged.
21572175func TestResolveChartJobs_CredentialFields (t * testing.T ) {
2158- insecure := true
21592176 ch := v1.Chart {
21602177 Name : "rancher" ,
21612178 Verify : true ,
@@ -2164,7 +2181,7 @@ func TestResolveChartJobs_CredentialFields(t *testing.T) {
21642181 CertFile : "/certs/client.crt" ,
21652182 KeyFile : "/certs/client.key" ,
21662183 CaFile : "/certs/ca.crt" ,
2167- InsecureSkipTLSVerify : & insecure ,
2184+ InsecureSkipTLSVerify : true ,
21682185 PlainHTTP : true ,
21692186 }
21702187
@@ -2195,14 +2212,47 @@ func TestResolveChartJobs_CredentialFields(t *testing.T) {
21952212 if opts .CaFile != ch .CaFile {
21962213 t .Errorf ("CaFile = %q, want %q" , opts .CaFile , ch .CaFile )
21972214 }
2198- if opts .InsecureSkipTLSVerify != derefInsecure ( ch .InsecureSkipTLSVerify ) {
2199- t .Errorf ("InsecureSkipTLSVerify = %v, want %v" , opts .InsecureSkipTLSVerify , derefInsecure ( ch .InsecureSkipTLSVerify ) )
2215+ if opts .InsecureSkipTLSVerify != ch .InsecureSkipTLSVerify {
2216+ t .Errorf ("InsecureSkipTLSVerify = %v, want %v" , opts .InsecureSkipTLSVerify , ch .InsecureSkipTLSVerify )
22002217 }
22012218 if opts .PlainHTTP != ch .PlainHTTP {
22022219 t .Errorf ("PlainHTTP = %v, want %v" , opts .PlainHTTP , ch .PlainHTTP )
22032220 }
22042221}
22052222
2223+ func TestResolveChartJobs_CaFilePrecedence (t * testing.T ) {
2224+ tests := []struct {
2225+ name string
2226+ cli string
2227+ annotation string
2228+ perChart string
2229+ want string
2230+ }{
2231+ {name : "annotation used when CLI and per-chart unset" , annotation : "/ann/ca.crt" , want : "/ann/ca.crt" },
2232+ {name : "per-chart wins over annotation" , annotation : "/ann/ca.crt" , perChart : "/chart/ca.crt" , want : "/chart/ca.crt" },
2233+ {name : "CLI wins over per-chart and annotation" , cli : "/cli/ca.crt" , annotation : "/ann/ca.crt" , perChart : "/chart/ca.crt" , want : "/cli/ca.crt" },
2234+ {name : "none set stays empty" , want : "" },
2235+ }
2236+
2237+ for _ , tc := range tests {
2238+ t .Run (tc .name , func (t * testing.T ) {
2239+ o := & flags.SyncOpts {CaFile : tc .cli }
2240+ a := map [string ]string {}
2241+ if tc .annotation != "" {
2242+ a [consts .ImageAnnotationCaFile ] = tc .annotation
2243+ }
2244+
2245+ jobs , err := resolveChartJobs (o , a , "/manifests" , []v1.Chart {{Name : "rancher" , CaFile : tc .perChart }})
2246+ if err != nil {
2247+ t .Fatalf ("resolveChartJobs: %v" , err )
2248+ }
2249+ if got := jobs [0 ].opts .ChartOpts .CaFile ; got != tc .want {
2250+ t .Errorf ("CaFile = %q, want %q" , got , tc .want )
2251+ }
2252+ })
2253+ }
2254+ }
2255+
22062256// TestResolveChartJobs_CredentialEnv pins that UsernameEnv/PasswordEnv are
22072257// resolved into ChartOpts.Username/Password via resolveChartCreds.
22082258func TestResolveChartJobs_CredentialEnv (t * testing.T ) {
@@ -2999,7 +3049,7 @@ func TestStoreImage_CAFileAndInsecure(t *testing.T) {
29993049 t .Run ("bad caFile without insecure returns error and stores nothing" , func (t * testing.T ) {
30003050 s := newTestStore (t )
30013051 insecure := false
3002- img := v1.Image {Name : ref , CaFile : missingCA , InsecureSkipTLSVerify : & insecure }
3052+ img := v1.Image {Name : ref , CaFile : missingCA , InsecureSkipTLSVerify : insecure }
30033053 err := storeImage (ctx , s , img , "" , false ,
30043054 defaultRootOpts (s .Root ), defaultCliOpts (), "" , "" , false )
30053055 if err == nil {
@@ -3017,7 +3067,7 @@ func TestStoreImage_CAFileAndInsecure(t *testing.T) {
30173067 t .Fatal (err )
30183068 }
30193069 insecure := false
3020- img := v1.Image {Name : ref , CaFile : junk , InsecureSkipTLSVerify : & insecure }
3070+ img := v1.Image {Name : ref , CaFile : junk , InsecureSkipTLSVerify : insecure }
30213071 err := storeImage (ctx , s , img , "" , false ,
30223072 defaultRootOpts (s .Root ), defaultCliOpts (), "" , "" , false )
30233073 if err == nil {
@@ -3031,7 +3081,7 @@ func TestStoreImage_CAFileAndInsecure(t *testing.T) {
30313081 // ignored and the pull still succeeds. If caFile were read first, the
30323082 // pull would error and nothing would be stored.
30333083 insecure := true
3034- img := v1.Image {Name : ref , CaFile : missingCA , InsecureSkipTLSVerify : & insecure }
3084+ img := v1.Image {Name : ref , CaFile : missingCA , InsecureSkipTLSVerify : insecure }
30353085 err := storeImage (ctx , s , img , "" , false ,
30363086 defaultRootOpts (s .Root ), defaultCliOpts (), "" , "" , false )
30373087 if err != nil {
@@ -3043,7 +3093,7 @@ func TestStoreImage_CAFileAndInsecure(t *testing.T) {
30433093 t .Run ("valid caFile without insecure is accepted" , func (t * testing.T ) {
30443094 s := newTestStore (t )
30453095 insecure := false
3046- img := v1.Image {Name : ref , CaFile : writeCAFile (t ), InsecureSkipTLSVerify : & insecure }
3096+ img := v1.Image {Name : ref , CaFile : writeCAFile (t ), InsecureSkipTLSVerify : insecure }
30473097 err := storeImage (ctx , s , img , "" , false ,
30483098 defaultRootOpts (s .Root ), defaultCliOpts (), "" , "" , false )
30493099 if err != nil {
0 commit comments