Skip to content

Commit

Permalink
🌱 Enable integers lint of KAL (#11887)
Browse files Browse the repository at this point in the history
* enable integers lint

Signed-off-by: sivchari <[email protected]>

* fix cmd/clusterctl

Signed-off-by: sivchari <[email protected]>

* add exclude rules

Signed-off-by: sivchari <[email protected]>

* move integers linter

Signed-off-by: sivchari <[email protected]>

---------

Signed-off-by: sivchari <[email protected]>
  • Loading branch information
sivchari authored Feb 26, 2025
1 parent 2a01368 commit d23093a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
10 changes: 9 additions & 1 deletion .golangci-kal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ linters-settings:
linters:
enable:
- "conditions" # Ensure conditions have the correct json tags and markers.
- "integers" # Ensure only int32 and int64 are used for integers.

# Per discussion in July 2024, we are keeping phase fields for now.
# See https://github.com/kubernetes-sigs/cluster-api/pull/10897#discussion_r1685929508
Expand All @@ -25,7 +26,6 @@ linters-settings:

# Linters below this line are disabled, pending conversation on how and when to enable them.
# - "commentstart" # Ensure comments start with the serialized version of the field name.
# - "integers" # Ensure only int32 and int64 are used for integers.
# - "jsontags" # Ensure every field has a json tag.
# - "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items.
# - "nobools" # Bools do not evolve over time, should use enums instead.
Expand Down Expand Up @@ -65,3 +65,11 @@ issues:
text: "Conditions field must be a slice of metav1.Condition"
linters:
- kal
- path: "api/v1beta1/*"
text: "type ClusterIPFamily should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements"
linters:
- kal
- path: "exp/ipam/api/v1alpha1/*|exp/ipam/api/v1beta1/*"
text: "field Prefix should not use an int, int8 or int16. Use int32 or int64 depending on bounding requirements"
linters:
- kal
6 changes: 3 additions & 3 deletions cmd/clusterctl/api/v1alpha3/metadata_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ type Metadata struct {
// ReleaseSeries maps a provider release series (major/minor) with a API Version of Cluster API (contract).
type ReleaseSeries struct {
// major version of the release series
Major uint `json:"major,omitempty"`
Major int32 `json:"major,omitempty"`

// minor version of the release series
Minor uint `json:"minor,omitempty"`
Minor int32 `json:"minor,omitempty"`

// contract defines the Cluster API contract supported by this series.
//
Expand All @@ -60,7 +60,7 @@ func init() {
// GetReleaseSeriesForVersion returns the release series for a given version.
func (m *Metadata) GetReleaseSeriesForVersion(version *version.Version) *ReleaseSeries {
for _, releaseSeries := range m.ReleaseSeries {
if version.Major() == releaseSeries.Major && version.Minor() == releaseSeries.Minor {
if version.Major() == uint(releaseSeries.Major) && version.Minor() == uint(releaseSeries.Minor) {
return &releaseSeries
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/clusterctl/client/cluster/upgrader_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (i *upgradeInfo) getContractsForUpgrade() []string {
contractsForUpgrade := sets.Set[string]{}
for _, releaseSeries := range i.metadata.ReleaseSeries {
// Drop the release series if older than the current version, because not relevant for upgrade.
if i.currentVersion.Major() > releaseSeries.Major || (i.currentVersion.Major() == releaseSeries.Major && i.currentVersion.Minor() > releaseSeries.Minor) {
if i.currentVersion.Major() > uint(releaseSeries.Major) || (i.currentVersion.Major() == uint(releaseSeries.Major) && i.currentVersion.Minor() > uint(releaseSeries.Minor)) {
continue
}
contractsForUpgrade.Insert(releaseSeries.Contract)
Expand All @@ -177,8 +177,8 @@ func (i *upgradeInfo) getLatestNextVersion(contract string) *version.Version {

// Drop the nextVersion version if not linked with the current
// release series or if it is a pre-release.
if nextVersion.Major() != releaseSeries.Major ||
nextVersion.Minor() != releaseSeries.Minor ||
if nextVersion.Major() != uint(releaseSeries.Major) ||
nextVersion.Minor() != uint(releaseSeries.Minor) ||
nextVersion.PreRelease() != "" {
continue
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/clusterctl/client/repository/repository_github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,9 @@ func Test_gitHubRepository_getLatestPatchRelease(t *testing.T) {
fmt.Fprint(w, "apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3\nreleaseSeries:\n - major: 0\n minor: 4\n contract: v1alpha4\n - major: 0\n minor: 5\n contract: v1alpha4\n - major: 0\n minor: 3\n contract: v1alpha3\n")
})

major0 := uint(0)
minor3 := uint(3)
minor4 := uint(4)
major0 := int32(0)
minor3 := int32(3)
minor4 := int32(4)

configVariablesClient := test.NewFakeVariableClient()

Expand All @@ -710,8 +710,8 @@ func Test_gitHubRepository_getLatestPatchRelease(t *testing.T) {
tests := []struct {
name string
field field
major *uint
minor *uint
major *int32
minor *int32
want string
wantErr bool
}{
Expand Down
6 changes: 3 additions & 3 deletions cmd/clusterctl/client/repository/repository_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func latestContractRelease(ctx context.Context, repo Repository, contract string

// If the Major or Minor version of the latest release doesn't match the release series for the current contract,
// return the latest patch release of the desired Major/Minor version.
if sv.Major() != releaseSeries.Major || sv.Minor() != releaseSeries.Minor {
if sv.Major() != uint(releaseSeries.Major) || sv.Minor() != uint(releaseSeries.Minor) {
return latestPatchRelease(ctx, repo, &releaseSeries.Major, &releaseSeries.Minor)
}
return latest, nil
Expand All @@ -84,7 +84,7 @@ func latestRelease(ctx context.Context, repo Repository) (string, error) {
}

// latestPatchRelease returns the latest patch release for a given Major and Minor version.
func latestPatchRelease(ctx context.Context, repo Repository, major, minor *uint) (string, error) {
func latestPatchRelease(ctx context.Context, repo Repository, major, minor *int32) (string, error) {
versions, err := repo.GetVersions(ctx)
if err != nil {
return "", errors.Wrapf(err, "failed to get repository versions")
Expand All @@ -101,7 +101,7 @@ func latestPatchRelease(ctx context.Context, repo Repository, major, minor *uint
continue
}

if (major != nil && sv.Major() != *major) || (minor != nil && sv.Minor() != *minor) {
if (major != nil && sv.Major() != uint(*major)) || (minor != nil && sv.Minor() != uint(*minor)) {
// skip versions that don't match the desired Major.Minor version.
continue
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d23093a

Please sign in to comment.