77 "strings"
88
99 "github.com/ghodss/yaml"
10+ version "github.com/hashicorp/go-version"
1011 "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
12+ "github.com/loft-sh/devspace/pkg/util/command"
1113 "github.com/loft-sh/devspace/pkg/util/log"
1214 "github.com/pkg/errors"
1315 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -72,6 +74,33 @@ func NewKubectlBuilder(path string, config *latest.DeploymentConfig, context, na
7274 }
7375}
7476
77+ // this function is called in Build function
78+ // to decide the --dry-run value
79+ var useOldDryRun = func (path string ) (bool , error ) {
80+ // compare kubectl version for --dry-run flag value
81+ out , err := command .NewStreamCommand (path , []string {"version" , "--client" , "--short" }).Output ()
82+ if err != nil {
83+ return false , err
84+ }
85+
86+ v1 , err := version .NewVersion (strings .TrimPrefix (strings .TrimSpace (string (out )), "Client Version: v" ))
87+ if err != nil {
88+
89+ return false , err
90+ }
91+
92+ v2 , err := version .NewVersion ("1.18.0" )
93+ if err != nil {
94+ return false , err
95+ }
96+
97+ if v1 .LessThan (v2 ) {
98+ return true , nil
99+ }
100+
101+ return false , nil
102+ }
103+
75104func (k * kubectlBuilder ) Build (manifest string , cmd RunCommand ) ([]* unstructured.Unstructured , error ) {
76105 args := []string {"create" }
77106 if k .context != "" && ! k .isInCluster {
@@ -81,7 +110,18 @@ func (k *kubectlBuilder) Build(manifest string, cmd RunCommand) ([]*unstructured
81110 args = append (args , "--namespace" , k .namespace )
82111 }
83112
84- args = append (args , "--dry-run" , "--output" , "yaml" , "--validate=false" )
113+ // decides which --dry-run value is to be used
114+ uodr , err := useOldDryRun (k .path )
115+ if err != nil {
116+ return nil , err
117+ }
118+
119+ if uodr {
120+ args = append (args , "--dry-run" , "--output" , "yaml" , "--validate=false" )
121+ } else {
122+ args = append (args , "--dry-run=client" , "--output" , "yaml" , "--validate=false" )
123+ }
124+
85125 if k .config .Kubectl .Kustomize != nil && * k .config .Kubectl .Kustomize {
86126 args = append (args , "--kustomize" , manifest )
87127 } else {
0 commit comments