@@ -481,6 +481,46 @@ dependencies.
481
481
Developers who need to manage dependencies in the ` vendor/ ` tree should read
482
482
the docs on [ using go modules to manage dependencies] ( /contributors/devel/sig-architecture/vendor.md ) .
483
483
484
+ ### Building Kubernetes Using A Specific Version of Go
485
+
486
+ There exists a [ ` .go-version ` ] ( https://github.com/kubernetes/kubernetes/blob/f563910656ad325a7e1f8ab5848746bc2eba4d7f/.go-version )
487
+ file in the root of the Kubernetes repo. This file defines what version of ` go ` should be used
488
+ to build Kubernetes. So, for example, if you'd like to build with ` go1.20.4 ` specifically, you
489
+ would change the contents of this file to just ` 1.20.4 ` .
490
+
491
+ The way that the build targets choose what ` go ` version to use is as follows:
492
+ - If the ` go ` version that exists on your system (determined by output of ` go version ` ) does
493
+ not match the version defined in ` .go-version ` , then default to the version specified in ` .go-version ` .
494
+ - If you do not want this behaviour, you can do one of the following:
495
+ - Set the ` GO_VERSION ` environment variable. ` GO_VERSION ` defines the _ desired_ version of
496
+ ` go ` to be used. Even if the ` go ` version on your system does not match the one in ` .go-version ` ,
497
+ the version specified by ` GO_VERSION ` will be used (even if it needs to be downloaded).
498
+ - The format of the version specified as part of ` GO_VERSION ` is the same as how a version
499
+ would be defined in the ` .go-version ` file. So if you wanted to build with ` go1.20.4 ` , you'd
500
+ set ` GO_VERSION=1.20.4 ` .
501
+ - Set the ` FORCE_HOST_GO ` environment variable to a non-empty value. This will skip all the above
502
+ logic and just use the ` go ` version that exists on your system's ` $PATH ` .
503
+
504
+ Some examples:
505
+
506
+ If you want to build using a ` go ` version (let's assume this is go1.20.4) that neither exists on your
507
+ system nor is the one that is specified in the ` .go-version ` file:
508
+
509
+ ```
510
+ GO_VERSION=1.20.4 make WHAT=cmd/<subsystem>
511
+ ```
512
+
513
+ If you want to build using the ` go ` version that exists on your system already and not really with what
514
+ exists in the ` .go-version ` file:
515
+ ```
516
+ FORCE_HOST_GO=y make WHAT=cmd/<subsystem>
517
+ ```
518
+
519
+ Or you can just change the contents of the ` .go-version ` file to your desired ` go ` version!
520
+ ` .go-version ` :
521
+ ```
522
+ 1.20.4
523
+ ```
484
524
485
525
## GitHub workflow
486
526
0 commit comments