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

Refactor reconciler logic #100

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions controllers/comparators/clusterrolebinding_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*

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 comparators

import (
v1 "k8s.io/api/rbac/v1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetClusterRoleBindingComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedCRB := deployed.(*v1.ClusterRoleBinding)
requestedCRB := requested.(*v1.ClusterRoleBinding)
return reflect.DeepEqual(deployedCRB.RoleRef, requestedCRB.RoleRef) &&
reflect.DeepEqual(deployedCRB.Subjects, requestedCRB.Subjects)
}
}
31 changes: 31 additions & 0 deletions controllers/comparators/networkpolicy_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*

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 comparators

import (
"k8s.io/api/networking/v1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetNetworkPolicyComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedCRB := deployed.(*v1.NetworkPolicy)
requestedCRB := requested.(*v1.NetworkPolicy)
return reflect.DeepEqual(deployedCRB.Spec, requestedCRB.Spec) &&
reflect.DeepEqual(deployedCRB.Labels, requestedCRB.Labels)
}
}
32 changes: 32 additions & 0 deletions controllers/comparators/peerAuthentication_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*

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 comparators

import (
istiosecv1beta1 "istio.io/client-go/pkg/apis/security/v1beta1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetPeerAuthenticationComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedPeerAuthentication := deployed.(*istiosecv1beta1.PeerAuthentication)
requestedPeerAuthentication := requested.(*istiosecv1beta1.PeerAuthentication)
return reflect.DeepEqual(deployedPeerAuthentication.Spec.Selector, requestedPeerAuthentication.Spec.Selector) &&
reflect.DeepEqual(deployedPeerAuthentication.Spec.Mtls, requestedPeerAuthentication.Spec.Mtls) &&
reflect.DeepEqual(deployedPeerAuthentication.Spec.PortLevelMtls, requestedPeerAuthentication.Spec.PortLevelMtls)
spolti marked this conversation as resolved.
Show resolved Hide resolved
}
}
30 changes: 30 additions & 0 deletions controllers/comparators/podmonitor_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*

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 comparators

import (
v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetPodMonitorComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedPodMonitor := deployed.(*v1.PodMonitor)
requestedPodMonitor := requested.(*v1.PodMonitor)
return reflect.DeepEqual(deployedPodMonitor.Spec, requestedPodMonitor.Spec)
}
}
19 changes: 16 additions & 3 deletions controllers/comparators/resourcecomparator.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/*

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 comparators

import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// ResourceComparator would compare deployed & requested resource. It would retrun `true` if both resource are same else it would return `false`
type ResourceComparator interface {
Compare(deployed client.Object, requested client.Object) bool
}
type ResourceComparator func(deployed client.Object, requested client.Object) bool
31 changes: 31 additions & 0 deletions controllers/comparators/rolebinding_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*

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 comparators

import (
v1 "k8s.io/api/rbac/v1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetRoleBindingComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedRB := deployed.(*v1.RoleBinding)
requestedRB := requested.(*v1.RoleBinding)
return reflect.DeepEqual(deployedRB.RoleRef, requestedRB.RoleRef) &&
reflect.DeepEqual(deployedRB.Subjects, requestedRB.Subjects)
}
}
46 changes: 38 additions & 8 deletions controllers/comparators/route_comparator.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
/*

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 comparators

import (
v1 "github.com/openshift/api/route/v1"
"k8s.io/apimachinery/pkg/api/equality"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type RouteComparator struct {
func GetMMRouteComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedRoute := deployed.(*v1.Route)
requestedRoute := requested.(*v1.Route)
return reflect.DeepEqual(deployedRoute.Spec.To, requestedRoute.Spec.To) &&
spolti marked this conversation as resolved.
Show resolved Hide resolved
reflect.DeepEqual(deployedRoute.Spec.Port, requestedRoute.Spec.Port) &&
reflect.DeepEqual(deployedRoute.Spec.WildcardPolicy, requestedRoute.Spec.WildcardPolicy) &&
reflect.DeepEqual(deployedRoute.Spec.Path, requestedRoute.Spec.Path) &&
reflect.DeepEqual(deployedRoute.Spec.TLS, requestedRoute.Spec.TLS) &&
reflect.DeepEqual(deployedRoute.Labels, requestedRoute.Labels)
}
}

func (c *RouteComparator) Compare(deployed client.Object, requested client.Object) bool {
deployedRoute := deployed.(*v1.Route)
requestedRoute := requested.(*v1.Route)
return equality.Semantic.DeepEqual(deployedRoute.Spec, requestedRoute.Spec) &&
equality.Semantic.DeepEqual(deployedRoute.Annotations, requestedRoute.Annotations) &&
equality.Semantic.DeepEqual(deployedRoute.Labels, requestedRoute.Labels)
func GetKServeRouteComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedRoute := deployed.(*v1.Route)
requestedRoute := requested.(*v1.Route)
return reflect.DeepEqual(deployedRoute.Spec.Host, requestedRoute.Spec.Host) &&
reflect.DeepEqual(deployedRoute.Spec.To, requestedRoute.Spec.To) &&
reflect.DeepEqual(deployedRoute.Spec.Port, requestedRoute.Spec.Port) &&
reflect.DeepEqual(deployedRoute.Spec.TLS, requestedRoute.Spec.TLS) &&
reflect.DeepEqual(deployedRoute.Spec.WildcardPolicy, requestedRoute.Spec.WildcardPolicy) &&
reflect.DeepEqual(deployedRoute.ObjectMeta.Labels, requestedRoute.ObjectMeta.Labels)
}
}
34 changes: 34 additions & 0 deletions controllers/comparators/service_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*

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 comparators

import (
v1 "k8s.io/api/core/v1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetServiceComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedService := deployed.(*v1.Service)
requestedService := requested.(*v1.Service)
return reflect.DeepEqual(deployedService.Spec.Ports, requestedService.Spec.Ports) &&
spolti marked this conversation as resolved.
Show resolved Hide resolved
reflect.DeepEqual(deployedService.Spec.Type, requestedService.Spec.Type) &&
reflect.DeepEqual(deployedService.Spec.Selector, requestedService.Spec.Selector) &&
reflect.DeepEqual(deployedService.Annotations, requestedService.Annotations) &&
reflect.DeepEqual(deployedService.Labels, requestedService.Labels)
}
}
26 changes: 26 additions & 0 deletions controllers/comparators/serviceaccount_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*

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 comparators

import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetServiceAccountComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
return true
spolti marked this conversation as resolved.
Show resolved Hide resolved
}
}
30 changes: 30 additions & 0 deletions controllers/comparators/servicemonitor_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*

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 comparators

import (
v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetServiceMonitorComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedServiceMonitor := deployed.(*v1.ServiceMonitor)
requestedServiceMonitor := requested.(*v1.ServiceMonitor)
return reflect.DeepEqual(deployedServiceMonitor.Spec, requestedServiceMonitor.Spec)
}
}
30 changes: 30 additions & 0 deletions controllers/comparators/smmr_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*

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 comparators

import (
v1 "maistra.io/api/core/v1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetServiceMeshMemberRollComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedSMMR := deployed.(*v1.ServiceMeshMemberRoll)
requestedSMMR := requested.(*v1.ServiceMeshMemberRoll)
return reflect.DeepEqual(deployedSMMR.Spec, requestedSMMR.Spec)
}
}
31 changes: 31 additions & 0 deletions controllers/comparators/telemetry_comparator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*

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 comparators

import (
telemetryv1alpha1 "istio.io/client-go/pkg/apis/telemetry/v1alpha1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetTelemetryComparator() ResourceComparator {
return func(deployed client.Object, requested client.Object) bool {
deployedTelemetry := deployed.(*telemetryv1alpha1.Telemetry)
requestedTelemetry := requested.(*telemetryv1alpha1.Telemetry)
return reflect.DeepEqual(deployedTelemetry.Spec.Selector, requestedTelemetry.Spec.Selector) &&
reflect.DeepEqual(deployedTelemetry.Spec.Metrics, requestedTelemetry.Spec.Metrics)
}
}
Loading