@@ -18,18 +18,19 @@ package validation
18
18
19
19
import (
20
20
"context"
21
- "errors"
22
21
"fmt"
23
22
"reflect"
24
23
"regexp"
25
24
"strings"
26
25
"time"
27
26
28
27
"github.com/docker/docker/api/types"
28
+ "github.com/pkg/errors"
29
29
30
30
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc"
31
31
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
32
32
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
33
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/parser"
33
34
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
34
35
latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
35
36
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
@@ -44,19 +45,21 @@ var (
44
45
)
45
46
46
47
// Process checks if the Skaffold pipeline is valid and returns all encountered errors as a concatenated string
47
- func Process (configs [] * latestV1. SkaffoldConfig ) error {
48
+ func Process (configs parser. SkaffoldConfigSet ) error {
48
49
var errs = validateImageNames (configs )
49
50
for _ , config := range configs {
50
- errs = append (errs , visitStructs (config , validateYamltags )... )
51
- errs = append (errs , validateDockerNetworkMode (config .Build .Artifacts )... )
52
- errs = append (errs , validateCustomDependencies (config .Build .Artifacts )... )
53
- errs = append (errs , validateSyncRules (config .Build .Artifacts )... )
54
- errs = append (errs , validatePortForwardResources (config .PortForward )... )
55
- errs = append (errs , validateJibPluginTypes (config .Build .Artifacts )... )
56
- errs = append (errs , validateLogPrefix (config .Deploy .Logs )... )
57
- errs = append (errs , validateArtifactTypes (config .Build )... )
58
- errs = append (errs , validateTaggingPolicy (config .Build )... )
59
- errs = append (errs , validateCustomTest (config .Test )... )
51
+ var cfgErrs []error
52
+ cfgErrs = append (cfgErrs , visitStructs (config .SkaffoldConfig , validateYamltags )... )
53
+ cfgErrs = append (cfgErrs , validateDockerNetworkMode (config .Build .Artifacts )... )
54
+ cfgErrs = append (cfgErrs , validateCustomDependencies (config .Build .Artifacts )... )
55
+ cfgErrs = append (cfgErrs , validateSyncRules (config .Build .Artifacts )... )
56
+ cfgErrs = append (cfgErrs , validatePortForwardResources (config .PortForward )... )
57
+ cfgErrs = append (cfgErrs , validateJibPluginTypes (config .Build .Artifacts )... )
58
+ cfgErrs = append (cfgErrs , validateLogPrefix (config .Deploy .Logs )... )
59
+ cfgErrs = append (cfgErrs , validateArtifactTypes (config .Build )... )
60
+ cfgErrs = append (cfgErrs , validateTaggingPolicy (config .Build )... )
61
+ cfgErrs = append (cfgErrs , validateCustomTest (config .Test )... )
62
+ errs = append (errs , wrapWithContext (config , cfgErrs ... )... )
60
63
}
61
64
errs = append (errs , validateArtifactDependencies (configs )... )
62
65
errs = append (errs , validateSingleKubeContext (configs )... )
@@ -100,35 +103,35 @@ func validateTaggingPolicy(bc latestV1.BuildConfig) (errs []error) {
100
103
101
104
// validateImageNames makes sure the artifact image names are unique and valid base names,
102
105
// without tags nor digests.
103
- func validateImageNames (configs [] * latestV1. SkaffoldConfig ) (errs []error ) {
104
- seen := make (map [string ]bool )
106
+ func validateImageNames (configs parser. SkaffoldConfigSet ) (errs []error ) {
107
+ seen := make (map [string ]string )
105
108
for _ , c := range configs {
106
109
for _ , a := range c .Build .Artifacts {
107
- if seen [a .ImageName ] {
108
- errs = append (errs , fmt .Errorf ("found duplicate images %q: artifact image names must be unique across all configurations" , a .ImageName ))
110
+ if prevSource , found := seen [a .ImageName ]; found {
111
+ errs = append (errs , fmt .Errorf ("duplicate image %q found in sources %s and %s : artifact image names must be unique across all configurations" , a .ImageName , prevSource , c . SourceFile ))
109
112
continue
110
113
}
111
114
112
- seen [a .ImageName ] = true
115
+ seen [a .ImageName ] = c . SourceFile
113
116
parsed , err := docker .ParseReference (a .ImageName )
114
117
if err != nil {
115
- errs = append (errs , fmt .Errorf ("invalid image %q: %w" , a .ImageName , err ))
118
+ errs = append (errs , wrapWithContext ( c , fmt .Errorf ("invalid image %q: %w" , a .ImageName , err )) ... )
116
119
continue
117
120
}
118
121
119
122
if parsed .Tag != "" {
120
- errs = append (errs , fmt .Errorf ("invalid image %q: no tag should be specified. Use taggers instead: https://skaffold.dev/docs/how-tos/taggers/" , a .ImageName ))
123
+ errs = append (errs , wrapWithContext ( c , fmt .Errorf ("invalid image %q: no tag should be specified. Use taggers instead: https://skaffold.dev/docs/how-tos/taggers/" , a .ImageName )) ... )
121
124
}
122
125
123
126
if parsed .Digest != "" {
124
- errs = append (errs , fmt .Errorf ("invalid image %q: no digest should be specified. Use taggers instead: https://skaffold.dev/docs/how-tos/taggers/" , a .ImageName ))
127
+ errs = append (errs , wrapWithContext ( c , fmt .Errorf ("invalid image %q: no digest should be specified. Use taggers instead: https://skaffold.dev/docs/how-tos/taggers/" , a .ImageName )) ... )
125
128
}
126
129
}
127
130
}
128
131
return
129
132
}
130
133
131
- func validateArtifactDependencies (configs [] * latestV1. SkaffoldConfig ) (errs []error ) {
134
+ func validateArtifactDependencies (configs parser. SkaffoldConfigSet ) (errs []error ) {
132
135
var artifacts []* latestV1.Artifact
133
136
for _ , c := range configs {
134
137
artifacts = append (artifacts , c .Build .Artifacts ... )
@@ -528,7 +531,7 @@ func validateLogPrefix(lc latestV1.LogsConfig) []error {
528
531
return nil
529
532
}
530
533
531
- func validateSingleKubeContext (configs [] * latestV1. SkaffoldConfig ) []error {
534
+ func validateSingleKubeContext (configs parser. SkaffoldConfigSet ) []error {
532
535
if len (configs ) < 2 {
533
536
return nil
534
537
}
@@ -565,3 +568,16 @@ func validateCustomTest(tcs []*latestV1.TestCase) (errs []error) {
565
568
}
566
569
return
567
570
}
571
+
572
+ func wrapWithContext (config * parser.SkaffoldConfigEntry , errs ... error ) []error {
573
+ var id string
574
+ if config .Metadata .Name != "" {
575
+ id = fmt .Sprintf ("module %q" , config .Metadata .Name )
576
+ } else {
577
+ id = fmt .Sprintf ("unnamed config at index %d" , config .SourceIndex )
578
+ }
579
+ for i := range errs {
580
+ errs [i ] = errors .Wrapf (errs [i ], "source: %s, %s" , config .SourceFile , id )
581
+ }
582
+ return errs
583
+ }
0 commit comments