@@ -41,6 +41,9 @@ type MutableEffectiveVersion interface {
41
41
}
42
42
43
43
type effectiveVersion struct {
44
+ // When true, BinaryVersion() returns the current binary version
45
+ useDefaultBuildBinaryVersion atomic.Bool
46
+ // Holds the last binary version stored in Set()
44
47
binaryVersion atomic.Pointer [version.Version ]
45
48
// If the emulationVersion is set by the users, it could only contain major and minor versions.
46
49
// In tests, emulationVersion could be the same as the binary version, or set directly,
@@ -51,6 +54,9 @@ type effectiveVersion struct {
51
54
}
52
55
53
56
func (m * effectiveVersion ) BinaryVersion () * version.Version {
57
+ if m .useDefaultBuildBinaryVersion .Load () {
58
+ return defaultBuildBinaryVersion ()
59
+ }
54
60
return m .binaryVersion .Load ()
55
61
}
56
62
@@ -89,6 +95,7 @@ func majorMinor(ver *version.Version) *version.Version {
89
95
90
96
func (m * effectiveVersion ) Set (binaryVersion , emulationVersion , minCompatibilityVersion * version.Version ) {
91
97
m .binaryVersion .Store (binaryVersion )
98
+ m .useDefaultBuildBinaryVersion .Store (false )
92
99
m .emulationVersion .Store (majorMinor (emulationVersion ))
93
100
m .minCompatibilityVersion .Store (majorMinor (minCompatibilityVersion ))
94
101
}
@@ -104,7 +111,7 @@ func (m *effectiveVersion) SetMinCompatibilityVersion(minCompatibilityVersion *v
104
111
func (m * effectiveVersion ) Validate () []error {
105
112
var errs []error
106
113
// Validate only checks the major and minor versions.
107
- binaryVersion := m .binaryVersion . Load ().WithPatch (0 )
114
+ binaryVersion := m .BinaryVersion ().WithPatch (0 )
108
115
emulationVersion := m .emulationVersion .Load ()
109
116
minCompatibilityVersion := m .minCompatibilityVersion .Load ()
110
117
@@ -123,10 +130,11 @@ func (m *effectiveVersion) Validate() []error {
123
130
return errs
124
131
}
125
132
126
- func newEffectiveVersion (binaryVersion * version.Version ) MutableEffectiveVersion {
133
+ func newEffectiveVersion (binaryVersion * version.Version , useDefaultBuildBinaryVersion bool ) MutableEffectiveVersion {
127
134
effective := & effectiveVersion {}
128
135
compatVersion := binaryVersion .SubtractMinor (1 )
129
136
effective .Set (binaryVersion , binaryVersion , compatVersion )
137
+ effective .useDefaultBuildBinaryVersion .Store (useDefaultBuildBinaryVersion )
130
138
return effective
131
139
}
132
140
@@ -135,25 +143,29 @@ func NewEffectiveVersion(binaryVer string) MutableEffectiveVersion {
135
143
return & effectiveVersion {}
136
144
}
137
145
binaryVersion := version .MustParse (binaryVer )
138
- return newEffectiveVersion (binaryVersion )
146
+ return newEffectiveVersion (binaryVersion , false )
147
+ }
148
+
149
+ func defaultBuildBinaryVersion () * version.Version {
150
+ verInfo := baseversion .Get ()
151
+ return version .MustParse (verInfo .String ()).WithInfo (verInfo )
139
152
}
140
153
141
154
// DefaultBuildEffectiveVersion returns the MutableEffectiveVersion based on the
142
155
// current build information.
143
156
func DefaultBuildEffectiveVersion () MutableEffectiveVersion {
144
- verInfo := baseversion .Get ()
145
- binaryVersion := version .MustParse (verInfo .String ()).WithInfo (verInfo )
157
+ binaryVersion := defaultBuildBinaryVersion ()
146
158
if binaryVersion .Major () == 0 && binaryVersion .Minor () == 0 {
147
159
return DefaultKubeEffectiveVersion ()
148
160
}
149
- return newEffectiveVersion (binaryVersion )
161
+ return newEffectiveVersion (binaryVersion , true )
150
162
}
151
163
152
164
// DefaultKubeEffectiveVersion returns the MutableEffectiveVersion based on the
153
165
// latest K8s release.
154
166
func DefaultKubeEffectiveVersion () MutableEffectiveVersion {
155
167
binaryVersion := version .MustParse (baseversion .DefaultKubeBinaryVersion ).WithInfo (baseversion .Get ())
156
- return newEffectiveVersion (binaryVersion )
168
+ return newEffectiveVersion (binaryVersion , false )
157
169
}
158
170
159
171
// ValidateKubeEffectiveVersion validates the EmulationVersion is equal to the binary version at 1.31 for kube components.
0 commit comments