Skip to content

Commit

Permalink
Merge pull request #100 from vaibhavjainwiz/refactor_reconciler
Browse files Browse the repository at this point in the history
Refactor reconciler logic
  • Loading branch information
openshift-ci[bot] authored Oct 23, 2023
2 parents 37771ee + 1b3a31c commit 5aed94d
Show file tree
Hide file tree
Showing 54 changed files with 3,339 additions and 1,569 deletions.
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)
}
}
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) &&
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) &&
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
}
}
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

0 comments on commit 5aed94d

Please sign in to comment.