...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/unmanageddetector/predicate.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/unmanageddetector

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package unmanageddetector
    16  
    17  import "sigs.k8s.io/controller-runtime/pkg/event"
    18  
    19  // UnmanagedDetectorPredicate is the predicate meant to be used by the
    20  // unmanaged-detector controller. It sets up unmanaged-detector such that it
    21  // handles Create events only.
    22  type UnmanagedDetectorPredicate struct{}
    23  
    24  func (UnmanagedDetectorPredicate) Create(_ event.CreateEvent) bool {
    25  	return true
    26  }
    27  
    28  // There is no scenario where unmanaged-detector would need to handle Update
    29  // events.
    30  //
    31  // Firstly, an Update event implies there had been a Create event already,
    32  // which would have been handled by unmanaged-detector.
    33  //
    34  // Secondly, once unmanaged-detector successfuly reconciles a resource once, it
    35  // never has to reconcile the resource again. This is because if the resource
    36  // is marked Unmanaged, then unmanaged-detector's job is done: the onus is now
    37  // on the user to create a ConfigConnectorContext. On the other hand, if the
    38  // resource is determined to be managed, then unmanaged-detector's job is also
    39  // done: it is not possible for a resource to later become unmanaged since
    40  // ConfigConnectorContext deletions are blocked if there are resources in its
    41  // namespace.
    42  //
    43  // Even if the resource had been created before unmanaged-detector came online
    44  // (e.g. if KCC is changed from cluster-mode to namespaced-mode), this is no
    45  // problem as well since controllers reconcile all resources they are
    46  // configured to watch when they first come up.
    47  func (UnmanagedDetectorPredicate) Update(_ event.UpdateEvent) bool {
    48  	return false
    49  }
    50  
    51  // KCC controllers in general do not handle Delete events since resources
    52  // deleted directly on the API server should not be reconciled. Instead,
    53  // user-requested deletions are handled via the updated DeletionTimestamp. That
    54  // is, user-requested deletions are handled via Update events, and as explained
    55  // above, there is no scenario where unmanaged-detector would need to handle
    56  // Update events.
    57  func (UnmanagedDetectorPredicate) Delete(_ event.DeleteEvent) bool {
    58  	return false
    59  }
    60  
    61  func (UnmanagedDetectorPredicate) Generic(_ event.GenericEvent) bool {
    62  	return false
    63  }
    64  

View as plain text