knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/configmap/watcher.go (about) 1 /* 2 Copyright 2018 The Knative Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package configmap 18 19 import ( 20 corev1 "k8s.io/api/core/v1" 21 ) 22 23 // Observer is the signature of the callbacks that notify an observer of the latest 24 // state of a particular configuration. An observer should not modify the provided 25 // ConfigMap, and should `.DeepCopy()` it for persistence (or otherwise process its 26 // contents). 27 type Observer func(*corev1.ConfigMap) 28 29 // Watcher defines the interface that a configmap implementation must implement. 30 type Watcher interface { 31 // Watch is called to register callbacks to be notified when a named ConfigMap changes. 32 Watch(string, ...Observer) 33 34 // Start is called to initiate the watches and provide a channel to signal when we should 35 // stop watching. When Start returns, all registered Observers will be called with the 36 // initial state of the ConfigMaps they are watching. 37 Start(<-chan struct{}) error 38 } 39 40 // DefaultingWatcher is similar to Watcher, but if a ConfigMap is absent, then a code provided 41 // default will be used. 42 type DefaultingWatcher interface { 43 Watcher 44 45 // WatchWithDefault is called to register callbacks to be notified when a named ConfigMap 46 // changes. The provided default value is always observed before any real ConfigMap with that 47 // name is. If the real ConfigMap with that name is deleted, then the default value is observed. 48 WatchWithDefault(cm corev1.ConfigMap, o ...Observer) 49 }