| /* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You 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 controllers |
| |
| import ( |
| "context" |
| ) |
| |
| import ( |
| "github.com/go-logr/logr" |
| |
| kube_core "k8s.io/api/core/v1" |
| |
| kube_ctrl "sigs.k8s.io/controller-runtime" |
| "sigs.k8s.io/controller-runtime/pkg/builder" |
| kube_client "sigs.k8s.io/controller-runtime/pkg/client" |
| "sigs.k8s.io/controller-runtime/pkg/event" |
| "sigs.k8s.io/controller-runtime/pkg/predicate" |
| ) |
| |
| type ServiceReconciler struct { |
| kube_client.Client |
| Log logr.Logger |
| } |
| |
| func (r *ServiceReconciler) SetupWithManager(mgr kube_ctrl.Manager) error { |
| return kube_ctrl.NewControllerManagedBy(mgr). |
| For(&kube_core.Service{}, builder.WithPredicates(serviceEvents)). |
| Complete(r) |
| } |
| |
| func (r *ServiceReconciler) Reconcile(ctx context.Context, req kube_ctrl.Request) (kube_ctrl.Result, error) { |
| return kube_ctrl.Result{}, nil |
| } |
| |
| // we only want create and update events |
| var serviceEvents = predicate.Funcs{ |
| CreateFunc: func(event event.CreateEvent) bool { |
| return true |
| }, |
| DeleteFunc: func(deleteEvent event.DeleteEvent) bool { |
| return false |
| }, |
| UpdateFunc: func(updateEvent event.UpdateEvent) bool { |
| return true |
| }, |
| GenericFunc: func(genericEvent event.GenericEvent) bool { |
| return false |
| }, |
| } |