-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compatibility rework: addressed comments
* change semicolon to comma as a separator in the provider templates charts * capi-contract annotation removed * unified separated capi contracts struct for cluster/provider templates * capi contracts status in management status * provider templates: validate capi contracts against core capi template * cluster templates: validate provider contracts against provider templates contracts in management status * renamed k0s -> k0smotron everywhere
- Loading branch information
Showing
31 changed files
with
610 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2024 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// isCAPIContractVersion determines whether a given string | ||
// represents a version in the CAPI contract version format (e.g. v1_v1beta1_v1alpha1, etc.). | ||
func isCAPIContractVersion(version string) bool { | ||
for _, v := range strings.Split(version, "_") { | ||
if !isCAPIContractSingleVersion(v) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
// isCAPIContractSingleVersion determines whether a given string | ||
// represents a single version in the CAPI contract version format (e.g. v1, v1beta1, v1alpha1, etc.). | ||
func isCAPIContractSingleVersion(version string) bool { | ||
if !strings.HasPrefix(version, "v") { | ||
return false | ||
} | ||
|
||
parts := strings.Split(version, "v") | ||
if len(parts) != 2 || parts[0] != "" || strings.IndexByte(version, '_') != -1 { // skip v1_v1beta1 list of versions | ||
return false | ||
} | ||
|
||
const ( | ||
alphaPrefix, betaPrefix = "alpha", "beta" | ||
) | ||
|
||
versionNumber := parts[1] | ||
alphaIndex := strings.Index(versionNumber, alphaPrefix) | ||
betaIndex := strings.Index(versionNumber, betaPrefix) | ||
|
||
if alphaIndex != -1 { | ||
return isNonMajor(versionNumber, alphaPrefix, alphaIndex) | ||
} else if betaIndex != -1 { | ||
return isNonMajor(versionNumber, betaPrefix, betaIndex) | ||
} | ||
|
||
_, err := strconv.Atoi(strings.TrimSpace(versionNumber)) | ||
return err == nil | ||
} | ||
|
||
func isNonMajor(version, prefix string, prefixIdx int) bool { | ||
majorVer := version[:prefixIdx] | ||
prefixedVer := version[prefixIdx+len(prefix):] | ||
|
||
if _, err := strconv.Atoi(majorVer); err != nil { | ||
return false | ||
} | ||
|
||
_, err := strconv.Atoi(prefixedVer) | ||
return err == nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2024 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v1alpha1 | ||
|
||
import "testing" | ||
|
||
func Test_isCAPIContractVersion(t *testing.T) { | ||
tests := []struct { | ||
version string | ||
isValid bool | ||
}{ | ||
{"v1", true}, | ||
{"v1alpha1", true}, | ||
{"v1beta1", true}, | ||
{"v2", true}, | ||
{"v3alpha2", true}, | ||
{"v33beta22", true}, | ||
{"v1alpha1_v1beta1", true}, | ||
{"v1alpha1v1alha2_v1beta1", false}, | ||
{"v4beta1", true}, | ||
{"invalid", false}, | ||
{"v1alpha", false}, | ||
{"v1beta", false}, | ||
{"v1alpha1beta1", false}, | ||
} | ||
|
||
for _, test := range tests { | ||
result := isCAPIContractVersion(test.version) | ||
if result != test.isValid { | ||
t.Errorf("isValidVersion(%q) = %v, want %v", test.version, result, test.isValid) | ||
} | ||
} | ||
} | ||
|
||
func Test_isCAPIContractSingleVersion(t *testing.T) { | ||
tests := []struct { | ||
version string | ||
isValid bool | ||
}{ | ||
{"v1", true}, | ||
{"v1alpha1", true}, | ||
{"v1beta1", true}, | ||
{"v2", true}, | ||
{"v3alpha2", true}, | ||
{"v33beta22", true}, | ||
{"v4beta1", true}, | ||
{"invalid", false}, | ||
{"v1alpha", false}, | ||
{"v1beta", false}, | ||
{"v1alpha1beta1", false}, | ||
{"v1alpha1_v1beta1", false}, | ||
} | ||
|
||
for _, test := range tests { | ||
result := isCAPIContractSingleVersion(test.version) | ||
if result != test.isValid { | ||
t.Errorf("isValidVersion(%q) = %v, want %v", test.version, result, test.isValid) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.