Skip to content

Commit 1e26d40

Browse files
authored
Merge pull request #12032 from sbueringer/pr-move-compat-version
🌱 Move contract version & GetCompatibleVersions to contract package
2 parents 4704d83 + 80329a5 commit 1e26d40

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

cmd/clusterctl/client/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
2828
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/repository"
2929
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/tree"
30+
"sigs.k8s.io/cluster-api/internal/contract"
3031
)
3132

3233
// Client is exposes the clusterctl high-level client library.
@@ -178,8 +179,8 @@ func New(ctx context.Context, path string, options ...Option) (Client, error) {
178179

179180
func newClusterctlClient(ctx context.Context, path string, options ...Option) (*clusterctlClient, error) {
180181
client := &clusterctlClient{
181-
currentContractVersion: cluster.CurrentContractVersion,
182-
getCompatibleContractVersions: cluster.GetCompatibleContractVersions,
182+
currentContractVersion: contract.Version,
183+
getCompatibleContractVersions: contract.GetCompatibleVersions,
183184
}
184185
for _, o := range options {
185186
o(client)

cmd/clusterctl/client/cluster/client.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,13 @@ import (
2424
"k8s.io/apimachinery/pkg/util/sets"
2525
"k8s.io/apimachinery/pkg/util/wait"
2626

27-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2827
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
2928
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/repository"
3029
yaml "sigs.k8s.io/cluster-api/cmd/clusterctl/client/yamlprocessor"
3130
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
31+
"sigs.k8s.io/cluster-api/internal/contract"
3232
)
3333

34-
var (
35-
// CurrentContractVersion is the contract version supported by this Cluster API version.
36-
// Note: Each Cluster API version supports one contract version, and by convention the contract version matches the current API version.
37-
CurrentContractVersion = clusterv1.GroupVersion.Version
38-
)
39-
40-
// GetCompatibleContractVersions return the list of contract version compatible with a given contract version.
41-
// NOTE: A contract version might be temporarily compatible with older contract versions e.g. to allow users time to transition to the new API.
42-
// NOTE: The return value must include also the contract version received in input.
43-
func GetCompatibleContractVersions(contract string) sets.Set[string] {
44-
compatibleContracts := sets.New(contract)
45-
// v1beta2 contract is temporarily be compatible with v1beta1 (until v1beta1 is EOL).
46-
if contract == "v1beta2" {
47-
compatibleContracts.Insert("v1beta1")
48-
}
49-
return compatibleContracts
50-
}
51-
5234
// Kubeconfig is a type that specifies inputs related to the actual
5335
// kubeconfig.
5436
type Kubeconfig struct {
@@ -233,8 +215,8 @@ func newClusterClient(kubeconfig Kubeconfig, configClient config.Client, options
233215
configClient: configClient,
234216
kubeconfig: kubeconfig,
235217
processor: yaml.NewSimpleProcessor(),
236-
currentContractVersion: CurrentContractVersion,
237-
getCompatibleContractVersions: GetCompatibleContractVersions,
218+
currentContractVersion: contract.Version,
219+
getCompatibleContractVersions: contract.GetCompatibleVersions,
238220
}
239221
for _, o := range options {
240222
o(client)

internal/contract/version.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package contract
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/util/sets"
21+
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23+
)
24+
25+
var (
26+
// Version is the contract version supported by this Cluster API version.
27+
// Note: Each Cluster API version supports one contract version, and by convention the contract version matches the current API version.
28+
Version = clusterv1.GroupVersion.Version
29+
)
30+
31+
// GetCompatibleVersions return the list of contract version compatible with a given contract version.
32+
// NOTE: A contract version might be temporarily compatible with older contract versions e.g. to allow users time to transition to the new API.
33+
// NOTE: The return value must include also the contract version received in input.
34+
func GetCompatibleVersions(contract string) sets.Set[string] {
35+
compatibleContracts := sets.New(contract)
36+
// v1beta2 contract is temporarily be compatible with v1beta1 (until v1beta1 is EOL).
37+
if contract == "v1beta2" {
38+
compatibleContracts.Insert("v1beta1")
39+
}
40+
return compatibleContracts
41+
}

0 commit comments

Comments
 (0)