generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from akgalwas/migrator-fixes
Fixes to make migrator up to date
- Loading branch information
Showing
12 changed files
with
260 additions
and
70 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
{ | ||
c65d5c9b-b321-4481-b567-d331d769ff1c, | ||
61e18f65-6c82-4fdd-97dc-cf51bfbbbeb2 | ||
7c6b4bd3-09d3-462f-b27c-992727b62eec, | ||
} |
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,71 @@ | ||
package shoot | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
"github.com/onsi/gomega" | ||
"github.com/onsi/gomega/types" | ||
"reflect" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
type ExtensionMatcher struct { | ||
toMatch interface{} | ||
fails []string | ||
} | ||
|
||
func NewExtensionMatcher(i interface{}) types.GomegaMatcher { | ||
return &ExtensionMatcher{ | ||
toMatch: i, | ||
} | ||
} | ||
|
||
func (m *ExtensionMatcher) Match(actual interface{}) (success bool, err error) { | ||
aExtensions, err := getExtension(actual) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
eExtensions, err := getExtension(m.toMatch) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
sort.Sort(Extensions(aExtensions)) | ||
sort.Sort(Extensions(eExtensions)) | ||
|
||
return gomega.BeComparableTo(eExtensions).Match(aExtensions) | ||
} | ||
|
||
func getExtension(i interface{}) ([]v1beta1.Extension, error) { | ||
switch v := i.(type) { | ||
case []v1beta1.Extension: | ||
return v, nil | ||
|
||
default: | ||
return []v1beta1.Extension{}, fmt.Errorf(`%w: %s`, errInvalidType, reflect.TypeOf(v)) | ||
} | ||
} | ||
|
||
type Extensions []v1beta1.Extension | ||
|
||
func (e Extensions) Len() int { | ||
return len(e) | ||
} | ||
|
||
func (e Extensions) Less(i, j int) bool { | ||
return e[i].Type < e[j].Type | ||
} | ||
|
||
func (e Extensions) Swap(i, j int) { | ||
e[i], e[j] = e[j], e[i] | ||
} | ||
|
||
func (m *ExtensionMatcher) NegatedFailureMessage(_ interface{}) string { | ||
return "expected should not equal actual" | ||
} | ||
|
||
func (m *ExtensionMatcher) FailureMessage(_ interface{}) string { | ||
return strings.Join(m.fails, "\n") | ||
} |
106 changes: 106 additions & 0 deletions
106
hack/shoot-comparator/pkg/shoot/extensionmatcher_test.go
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,106 @@ | ||
package shoot | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
. "github.com/onsi/ginkgo/v2" //nolint:revive | ||
. "github.com/onsi/gomega" //nolint:revive | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
var _ = Describe(":: extension matcher :: ", func() { | ||
emptyExt := make([]v1beta1.Extension, 0) | ||
|
||
DescribeTable( | ||
"checking invalid args :: ", | ||
testExtensionInvalidArgs, | ||
Entry("when actual is not of Extension type", v1beta1.Shoot{}, emptyExt), | ||
Entry("when expected is not of Extension type", emptyExt, v1beta1.Shoot{}), | ||
Entry("when actual is nil", nil, emptyExt), | ||
Entry("when expected is nil", emptyExt, nil), | ||
) | ||
|
||
dnsExtEnabled := getDNSExtension(false, true) | ||
dnsExtDisabled := getDNSExtension(true, false) | ||
networkingExtDisabled := getNetworkingExtension(true) | ||
certificateExtEnabled := getCertificateExtension(false, true) | ||
|
||
DescribeTable( | ||
"checking results :: ", | ||
testExtensionResults, | ||
Entry( | ||
"should match empty values", | ||
emptyExt, | ||
emptyExt, | ||
true, | ||
), | ||
Entry( | ||
"should match identical tables", | ||
[]v1beta1.Extension{dnsExtEnabled, networkingExtDisabled, certificateExtEnabled}, | ||
[]v1beta1.Extension{networkingExtDisabled, certificateExtEnabled, dnsExtEnabled}, | ||
true, | ||
), | ||
Entry( | ||
"should detect extension differs", | ||
[]v1beta1.Extension{dnsExtEnabled, networkingExtDisabled, certificateExtEnabled}, | ||
[]v1beta1.Extension{dnsExtDisabled, networkingExtDisabled, certificateExtEnabled}, | ||
false, | ||
), | ||
Entry( | ||
"should detect redundant extension", | ||
[]v1beta1.Extension{dnsExtEnabled, networkingExtDisabled, certificateExtEnabled}, | ||
[]v1beta1.Extension{networkingExtDisabled, certificateExtEnabled}, | ||
false, | ||
), | ||
Entry( | ||
"should detect missing extension", | ||
[]v1beta1.Extension{networkingExtDisabled, certificateExtEnabled}, | ||
[]v1beta1.Extension{dnsExtEnabled, networkingExtDisabled, certificateExtEnabled}, | ||
false, | ||
), | ||
) | ||
}) | ||
|
||
func testExtensionInvalidArgs(actual, expected interface{}) { | ||
matcher := NewExtensionMatcher(expected) | ||
_, err := matcher.Match(actual) | ||
Expect(err).To(HaveOccurred()) | ||
} | ||
|
||
func testExtensionResults(actual, expected interface{}, expectedMatch bool) { | ||
matcher := NewExtensionMatcher(expected) | ||
actualMatch, err := matcher.Match(actual) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(actualMatch).Should(Equal(expectedMatch), matcher.FailureMessage(actual)) | ||
} | ||
|
||
func getDNSExtension(disabled bool, replicationEnabled bool) v1beta1.Extension { | ||
json := fmt.Sprintf(`{apiVersion: "service.dns.extensions.gardener.cloud/v1alpha1", kind: "DNSConfig", dnsProviderReplication: {enabled: %v}}`, replicationEnabled) | ||
|
||
return v1beta1.Extension{ | ||
Type: "shoot-dns-service", | ||
Disabled: &disabled, | ||
ProviderConfig: &runtime.RawExtension{ | ||
Raw: []byte(json), | ||
}, | ||
} | ||
} | ||
|
||
func getNetworkingExtension(disabled bool) v1beta1.Extension { | ||
return v1beta1.Extension{ | ||
Type: "shoot-networking-service", | ||
Disabled: &disabled, | ||
} | ||
} | ||
|
||
func getCertificateExtension(disabled bool, shootIssuersEnabled bool) v1beta1.Extension { | ||
json := fmt.Sprintf(`{apiVersion: "service.cert.extensions.gardener.cloud/v1alpha1", kind: "CertConfig", shootIssuers: {enabled: %v}}`, shootIssuersEnabled) | ||
|
||
return v1beta1.Extension{ | ||
Type: "shoot-cert-service", | ||
Disabled: &disabled, | ||
ProviderConfig: &runtime.RawExtension{ | ||
Raw: []byte(json), | ||
}, | ||
} | ||
} |
Oops, something went wrong.