-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize CRD and webhook version related methods in Config
Signed-off-by: Adrian Orive <adrian.orive.oneca@gmail.com>
- Loading branch information
Showing
9 changed files
with
173 additions
and
77 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
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,35 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
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 util | ||
|
||
import ( | ||
"sigs.k8s.io/kubebuilder/v3/pkg/config" | ||
) | ||
|
||
// HasDifferentCRDVersion returns true if any other CRD version is tracked in the project configuration. | ||
func HasDifferentCRDVersion(config config.Config, crdVersion string) bool { | ||
return hasDifferentAPIVersion(config.ListCRDVersions(), crdVersion) | ||
} | ||
|
||
// HasDifferentWebhookVersion returns true if any other webhook version is tracked in the project configuration. | ||
func HasDifferentWebhookVersion(config config.Config, webhookVersion string) bool { | ||
return hasDifferentAPIVersion(config.ListWebhookVersions(), webhookVersion) | ||
} | ||
|
||
func hasDifferentAPIVersion(versions []string, version string) bool { | ||
return !(len(versions) == 0 || (len(versions) == 1 && versions[0] == version)) | ||
} |
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,45 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
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 util | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestPlugin(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Plugin Util Suite") | ||
} | ||
|
||
var _ = Describe("hasDifferentAPIVersion", func() { | ||
DescribeTable("should return false", | ||
func(versions []string) { Expect(hasDifferentAPIVersion(versions, "v1")).To(BeFalse()) }, | ||
Entry("for an empty list of versions", []string{}), | ||
Entry("for a list of only that version", []string{"v1"}), | ||
) | ||
|
||
DescribeTable("should return true", | ||
func(versions []string) { Expect(hasDifferentAPIVersion(versions, "v1")).To(BeTrue()) }, | ||
Entry("for a list of only a different version", []string{"v2"}), | ||
Entry("for a list of several different versions", []string{"v2", "v3"}), | ||
Entry("for a list of several versions containing that version", []string{"v1", "v2"}), | ||
) | ||
}) |
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