Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Enable integers lint of KAL #11887

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .golangci-kal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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.
- "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.