Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
m00g3n committed Oct 17, 2024
1 parent 74a0c12 commit e0c9da5
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 92 deletions.
10 changes: 5 additions & 5 deletions hack/shoot-comparator/pkg/runtime/raw_extension_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ func (m *RawExtensionMatcher) Match(actual interface{}) (bool, error) {
return true, nil
}

aRawExtension, err := utilz.Get[runtime.RawExtension](actual)
rawXtActual, err := utilz.Get[runtime.RawExtension](actual)
if err != nil {
return false, err
}

eRawExtension, err := utilz.Get[runtime.RawExtension](m.toMatch)
rasXtToMatch, err := utilz.Get[runtime.RawExtension](m.toMatch)
if err != nil {
return false, err
}

sort.Sort(sortBytes(aRawExtension.Raw))
sort.Sort(sortBytes(eRawExtension.Raw))
sort.Sort(sortBytes(rawXtActual.Raw))
sort.Sort(sortBytes(rasXtToMatch.Raw))

return gomega.BeComparableTo(aRawExtension.Raw).Match(eRawExtension.Raw)
return gomega.BeComparableTo(rawXtActual.Raw).Match(rasXtToMatch.Raw)
}

func (m *RawExtensionMatcher) NegatedFailureMessage(_ interface{}) string {
Expand Down
133 changes: 84 additions & 49 deletions hack/shoot-comparator/pkg/shoot/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,28 @@ func (m *Matcher) Match(actual interface{}) (success bool, err error) {
path: "metadata/namespace",
},
{
GomegaMatcher: gstruct.MatchElements(idExtension, gstruct.IgnoreExtras, extensions(shootActual.Spec.Extensions)),
actual: shootToMatch.Spec.Extensions,
GomegaMatcher: gstruct.MatchElements(idExtension, gstruct.IgnoreMissing, extensions(shootToMatch.Spec.Extensions)),
actual: shootActual.Spec.Extensions,
path: "spec/extensions",
},
{
GomegaMatcher: gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Version": gomega.BeComparableTo(shootActual.Spec.Kubernetes.Version),
"EnableStaticTokenKubeconfig": gomega.BeComparableTo(shootActual.Spec.Kubernetes.EnableStaticTokenKubeconfig),
"KubeAPIServer": newKubeAPIServerMatcher(shootActual.Spec.Kubernetes),
GomegaMatcher: gstruct.MatchFields(gstruct.IgnoreMissing, gstruct.Fields{
"ClusterAutoscaler": gstruct.Ignore(),
"KubeAPIServer": newKubeAPIServerMatcher(shootToMatch.Spec.Kubernetes),
"KubeControllerManager": gstruct.Ignore(),
"KubeScheduler": gstruct.Ignore(),
"KubeProxy": gstruct.Ignore(),
"Kubelet": gstruct.Ignore(),
"Version": gomega.BeComparableTo(shootToMatch.Spec.Kubernetes.Version),
"VerticalPodAutoscaler": gstruct.Ignore(),
"EnableStaticTokenKubeconfig": gomega.BeComparableTo(shootToMatch.Spec.Kubernetes.EnableStaticTokenKubeconfig),
}),
actual: shootToMatch.Spec.Kubernetes,
actual: shootActual.Spec.Kubernetes,
path: "spec/kubernetes",
},
{
GomegaMatcher: newNetworkingMatcher(shootActual.Spec),
actual: shootToMatch.Spec.Networking,
GomegaMatcher: newNetworkingMatcher(shootToMatch.Spec),
actual: shootActual.Spec.Networking,
path: "spec/networking",
},
{
Expand All @@ -107,17 +113,17 @@ func (m *Matcher) Match(actual interface{}) (success bool, err error) {
path: "spec/secretBindingName",
},
{
GomegaMatcher: newDNSMatcher(shootActual.Spec.DNS),
GomegaMatcher: newDNSMatcher(shootToMatch.Spec.DNS),
path: "spec/dns",
actual: shootToMatch.Spec.DNS,
actual: shootActual.Spec.DNS,
},
{
GomegaMatcher: gstruct.MatchElements(
idToleration,
gstruct.IgnoreExtras,
tolerations(shootActual.Spec.Tolerations),
gstruct.IgnoreMissing,
tolerations(shootToMatch.Spec.Tolerations),
),
actual: shootToMatch.Spec.Tolerations,
actual: shootActual.Spec.Tolerations,
path: "spec/tolerations",
},
{
Expand All @@ -141,8 +147,8 @@ func (m *Matcher) Match(actual interface{}) (success bool, err error) {
path: "spec/provider",
},
{
GomegaMatcher: gomega.SatisfyAll(mapMatchers(shootActual.Labels)...),
actual: shootToMatch.Labels,
GomegaMatcher: gomega.SatisfyAll(mapMatchers(shootToMatch.Labels)...),
actual: shootActual.Labels,
path: "metadata/labels",
},
{
Expand Down Expand Up @@ -244,20 +250,25 @@ func providers(ps []v1beta1.DNSProvider) gstruct.Elements {
out := map[string]types.GomegaMatcher{}
for _, p := range ps {
ID := idProvider(p)

domainsMatcher := gomega.BeNil()
if p.Domains != nil {
domainsMatcher = gstruct.PointTo(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Include": gomega.ContainElements(p.Domains.Include),
}))
domainsMatcher = gstruct.PointTo(
gstruct.MatchFields(
gstruct.IgnoreMissing,
gstruct.Fields{
"Include": gomega.ContainElements(p.Domains.Include),
}))
}

out[ID] = gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Primary": gomega.Equal(p.Primary),
"SecretName": gomega.Equal(p.SecretName),
"Type": gomega.Equal(p.Type),
"Domains": domainsMatcher,
})
out[ID] = gstruct.MatchFields(
gstruct.IgnoreMissing,
gstruct.Fields{
"Primary": gomega.Equal(p.Primary),
"SecretName": gomega.Equal(p.SecretName),
"Type": gomega.Equal(p.Type),
"Domains": domainsMatcher,
"Zones": gstruct.Ignore(),
})
}

return out
Expand All @@ -268,11 +279,15 @@ func newDNSMatcher(dns *v1beta1.DNS) types.GomegaMatcher {
return gomega.BeNil()
}

return gstruct.PointTo(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Domain": gomega.BeComparableTo(dns.Domain),
"Providers": gstruct.MatchElements(idProvider, gstruct.IgnoreExtras,
providers(dns.Providers)),
}))
return gstruct.PointTo(gstruct.MatchFields(
gstruct.IgnoreMissing,
gstruct.Fields{
"Domain": gomega.BeComparableTo(dns.Domain),
"Providers": gstruct.MatchElements(
idProvider,
gstruct.IgnoreMissing,
providers(dns.Providers)),
}))
}

func newMaintenanceMatcher(spec v1beta1.ShootSpec) types.GomegaMatcher {
Expand All @@ -290,12 +305,17 @@ func newNetworkingMatcher(spec v1beta1.ShootSpec) types.GomegaMatcher {
return gomega.BeNil()
}

return gstruct.PointTo(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Type": gomega.BeComparableTo(spec.Networking.Type),
"Nodes": gomega.BeComparableTo(spec.Networking.Nodes),
"Pods": gomega.BeComparableTo(spec.Networking.Pods),
"Services": gomega.BeComparableTo(spec.Networking.Services),
}))
return gstruct.PointTo(
gstruct.MatchFields(
gstruct.IgnoreMissing,
gstruct.Fields{
"Type": gomega.BeComparableTo(spec.Networking.Type),
"Nodes": gomega.BeComparableTo(spec.Networking.Nodes),
"Pods": gomega.BeComparableTo(spec.Networking.Pods),
"Services": gomega.BeComparableTo(spec.Networking.Services),
"ProviderConfig": gstruct.Ignore(),
"IPFamilies": gstruct.Ignore(),
}))
}

func newKubeAPIServerMatcher(k v1beta1.Kubernetes) types.GomegaMatcher {
Expand All @@ -304,9 +324,23 @@ func newKubeAPIServerMatcher(k v1beta1.Kubernetes) types.GomegaMatcher {
}

return gstruct.PointTo(gstruct.MatchFields(
gstruct.IgnoreExtras,
gstruct.IgnoreMissing,
gstruct.Fields{
"OIDCConfig": newOIDCConfigMatcher(k.KubeAPIServer),
"OIDCConfig": newOIDCConfigMatcher(k.KubeAPIServer),
"KubernetesConfig": gstruct.Ignore(),
"AdmissionPlugins": gstruct.Ignore(),
"APIAudiences": gstruct.Ignore(),
"AuditConfig": gstruct.Ignore(),
"RuntimeConfig": gstruct.Ignore(),
"ServiceAccountConfig": gstruct.Ignore(),
"WatchCacheSizes": gstruct.Ignore(),
"Requests": gstruct.Ignore(),
"EnableAnonymousAuthentication": gstruct.Ignore(),
"EventTTL": gstruct.Ignore(),
"Logging": gstruct.Ignore(),
"DefaultNotReadyTolerationSeconds": gstruct.Ignore(),
"DefaultUnreachableTolerationSeconds": gstruct.Ignore(),
"EncryptionConfig": gstruct.Ignore(),
},
))
}
Expand All @@ -317,17 +351,18 @@ func newOIDCConfigMatcher(c *v1beta1.KubeAPIServerConfig) types.GomegaMatcher {
}

return gstruct.PointTo(gstruct.MatchFields(
gstruct.IgnoreExtras,
gstruct.IgnoreMissing,
gstruct.Fields{
"CABundle": gomega.BeComparableTo(c.OIDCConfig.CABundle),
"ClientID": gomega.BeComparableTo(c.OIDCConfig.ClientID),
"GroupsClaim": gomega.BeComparableTo(c.OIDCConfig.GroupsClaim),
"GroupsPrefix": gomega.BeComparableTo(c.OIDCConfig.GroupsPrefix),
"IssuerURL": gomega.BeComparableTo(c.OIDCConfig.IssuerURL),
"RequiredClaims": gomega.BeComparableTo(c.OIDCConfig.RequiredClaims),
"SigningAlgs": gomega.ContainElements(c.OIDCConfig.SigningAlgs),
"UsernameClaim": gomega.BeComparableTo(c.OIDCConfig.UsernameClaim),
"UsernamePrefix": gomega.BeComparableTo(c.OIDCConfig.UsernamePrefix),
"CABundle": gomega.BeComparableTo(c.OIDCConfig.CABundle),
"ClientID": gomega.BeComparableTo(c.OIDCConfig.ClientID),
"GroupsClaim": gomega.BeComparableTo(c.OIDCConfig.GroupsClaim),
"GroupsPrefix": gomega.BeComparableTo(c.OIDCConfig.GroupsPrefix),
"IssuerURL": gomega.BeComparableTo(c.OIDCConfig.IssuerURL),
"RequiredClaims": gomega.BeComparableTo(c.OIDCConfig.RequiredClaims),
"SigningAlgs": gomega.ContainElements(c.OIDCConfig.SigningAlgs),
"UsernameClaim": gomega.BeComparableTo(c.OIDCConfig.UsernameClaim),
"UsernamePrefix": gomega.BeComparableTo(c.OIDCConfig.UsernamePrefix),
"ClientAuthentication": gstruct.Ignore(),
},
))
}
Expand Down
23 changes: 9 additions & 14 deletions hack/shoot-comparator/pkg/shoot/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ var _ = Describe(":: shoot matcher :: ", func() {
Entry(
"should skip extra metadata/annotations",
deepCp(empty, withAnnotations(map[string]string{"test": "me"})),
deepCp(empty, withAnnotations(map[string]string{
"test": "me",
"dżułel": "wuz@here",
})),
deepCp(empty, withAnnotations(map[string]string{"test": "me", "dżułel": "wuz@here"})),
true,
),
Entry(
Expand All @@ -117,11 +114,8 @@ var _ = Describe(":: shoot matcher :: ", func() {
),
Entry(
"should skip extra labels",
deepCp(empty, withLabels(map[string]string{"test": "me", "dżułel": "wuz@here"})),
deepCp(empty, withLabels(map[string]string{"test": "me"})),
deepCp(empty, withLabels(map[string]string{
"test": "me",
"dżułel": "wuz@here",
})),
true,
),
Entry(
Expand Down Expand Up @@ -833,6 +827,7 @@ var _ = Describe(":: shoot matcher :: ", func() {
true,
),
Entry(

"should find differences in spec/provider/type",
deepCp(empty, withShootSpec(v1beta1.ShootSpec{
Provider: v1beta1.Provider{
Expand Down Expand Up @@ -930,8 +925,7 @@ var _ = Describe(":: shoot matcher :: ", func() {
{
Name: "iTwurkz",
Annotations: map[string]string{
"test": "me",
"dżułel": "wuz@here",
"test": "me",
},
},
},
Expand All @@ -943,7 +937,8 @@ var _ = Describe(":: shoot matcher :: ", func() {
{
Name: "iTwurkz",
Annotations: map[string]string{
"test": "me",
"test": "me",
"dżułel": "wuz@here",
},
},
},
Expand Down Expand Up @@ -984,8 +979,7 @@ var _ = Describe(":: shoot matcher :: ", func() {
{
Name: "iTwurkz",
Labels: map[string]string{
"test": "me",
"dżułel": "wuz@here",
"test": "me",
},
},
},
Expand All @@ -997,7 +991,8 @@ var _ = Describe(":: shoot matcher :: ", func() {
{
Name: "iTwurkz",
Labels: map[string]string{
"test": "me",
"test": "me",
"dżułel": "wuz@here",
},
},
},
Expand Down
Loading

0 comments on commit e0c9da5

Please sign in to comment.