-
Notifications
You must be signed in to change notification settings - Fork 60
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 #100 from vaibhavjainwiz/refactor_reconciler
Refactor reconciler logic
- Loading branch information
Showing
54 changed files
with
3,339 additions
and
1,569 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
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) | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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 |
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,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) | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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 | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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) | ||
} | ||
} |
Oops, something went wrong.