Documentation ¶
Index ¶
- Constants
- Variables
- func Base64StringDecode(encodedStr string) (string, error)
- func CheckAndInstallCRD(crdconfig *rest.Config, pathname string) error
- func ConvertLabels(labelSelector *metav1.LabelSelector) (labels.Selector, error)
- func DetectClusterRegistry(ctx context.Context, clReader client.Reader)
- func EnterFnString() string
- func ExitFuString(s string)
- func ExtractUserAndGroup(annotations map[string]string) (string, []string)
- func FilteClustersByIdentity(authClient kubernetes.Interface, object runtime.Object, ...) error
- func GetFnName() string
- func GetManagedClusterNamespace(secretName string) string
- func IfClusterAdmin(user string, groups []string) bool
- func InstanceDeepCopy(a, b interface{}) error
- func IsReadyACMClusterRegistry(clReader client.Reader) bool
- func PlaceByGenericPlacmentFields(kubeclient client.Client, placement appv1alpha1.GenericPlacementFields, ...) (map[string]*spokeClusterV1.ManagedCluster, error)
- func ToPlaceLocal(placement *appv1alpha1.Placement) bool
- func ValidateK8sLabel(s string) string
- type EventRecorder
Constants ¶
const ( // #nosec G101 ACMClusterSecretLabel = "apps.open-cluster-management.io/secret-type" // #nosec G101 ArgocdClusterSecretLabel = "apps.open-cluster-management.io/acm-cluster" // #nosec G101 ACMClusterNameLabel = "apps.open-cluster-management.io/cluster-name" )
const NoiseLogLel = 5
NoiseLogLel - information inside "important functions"
const QuiteLogLel = 4
QuiteLogLel - "important" information
const VeryNoisy = 10
VeryNoisy = show call stack, routine and everything
Variables ¶
var ( AdminUsers = map[string]bool{ "admin": true, "multicluster-observability-operator": true, "openshift-gitops-argocd-application-controller": true, } AdminGroups = map[string]bool{ "masters": true, "cluster-admins": true, } )
var AcmClusterSecretPredicateFunc = predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { oldSecret, ok := e.ObjectOld.(*v1.Secret) if !ok { return false } newSecret, nok := e.ObjectNew.(*v1.Secret) if !nok { return false } oldSecretType, ok := e.ObjectOld.GetLabels()[ACMClusterSecretLabel] newSecretType, nok := e.ObjectNew.GetLabels()[ACMClusterSecretLabel] if ok && oldSecretType == "acm-cluster" { klog.Infof("Update a old ACM cluster secret, old: %v/%v, new: %v/%v", oldSecret.Namespace, oldSecret.Name, newSecret.Namespace, newSecret.Name) return true } if nok && newSecretType == "acm-cluster" { klog.Infof("Update a new ACM cluster secret, old: %v/%v, new: %v/%v", oldSecret.Namespace, oldSecret.Name, newSecret.Namespace, newSecret.Name) return true } klog.Infof("Not a ACM cluster secret update, old: %v/%v, new: %v/%v", oldSecret.Namespace, oldSecret.Name, newSecret.Namespace, newSecret.Name) return false }, CreateFunc: func(e event.CreateEvent) bool { SecretType, ok := e.Object.GetLabels()[ACMClusterSecretLabel] if !ok { return false } else if SecretType != "acm-cluster" { return false } klog.Infof("Create a ACM cluster secret: %v/%v", e.Object.GetNamespace(), e.Object.GetName()) return true }, DeleteFunc: func(e event.DeleteEvent) bool { SecretType, ok := e.Object.GetLabels()[ACMClusterSecretLabel] if !ok { return false } else if SecretType != "acm-cluster" { return false } klog.Infof("Delete a ACM cluster secret: %v/%v", e.Object.GetNamespace(), e.Object.GetName()) return true }, }
AcmClusterSecretPredicateFunc defines predicate function for ACM cluster secrets watch
var ArgocdClusterSecretPredicateFunc = predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { oldSecret, ok := e.ObjectOld.(*v1.Secret) if !ok { return false } newSecret, nok := e.ObjectNew.(*v1.Secret) if !nok { return false } oldSecretType, ok := e.ObjectOld.GetLabels()[ArgocdClusterSecretLabel] newSecretType, nok := e.ObjectNew.GetLabels()[ArgocdClusterSecretLabel] if ok && oldSecretType == "true" { klog.Infof("Update a old ArgoCD cluster secret, old: %v/%v, new: %v/%v", oldSecret.Namespace, oldSecret.Name, newSecret.Namespace, newSecret.Name) return true } if nok && newSecretType == "true" { klog.Infof("Update a new Argocd cluster secret, old: %v/%v, new: %v/%v", oldSecret.Namespace, oldSecret.Name, newSecret.Namespace, newSecret.Name) return true } klog.Infof("Not a ArgoCD cluster secret update, old: %v/%v, new: %v/%v", oldSecret.Namespace, oldSecret.Name, newSecret.Namespace, newSecret.Name) return false }, CreateFunc: func(e event.CreateEvent) bool { SecretType, ok := e.Object.GetLabels()[ArgocdClusterSecretLabel] if !ok { return false } else if SecretType != "true" { return false } klog.Infof("Create a ArgoCD cluster secret: %v/%v", e.Object.GetNamespace(), e.Object.GetName()) return true }, DeleteFunc: func(e event.DeleteEvent) bool { SecretType, ok := e.Object.GetLabels()[ArgocdClusterSecretLabel] if !ok { return false } else if SecretType != "true" { return false } klog.Infof("Delete a ArgoCD cluster secret: %v/%v", e.Object.GetNamespace(), e.Object.GetName()) return true }, }
ArgocdClusterSecretPredicateFunc defines predicate function for ArgoCD cluster secrets watch
var ArgocdServerPredicateFunc = predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { oldService, ok := e.ObjectOld.(*v1.Service) if !ok { return false } newService, nok := e.ObjectNew.(*v1.Service) if !nok { return false } oldArgocdServerLabel := e.ObjectOld.GetLabels() newArgocdServerLabel := e.ObjectNew.GetLabels() if oldArgocdServerLabel != nil && oldArgocdServerLabel["app.kubernetes.io/part-of"] == "argocd" && oldArgocdServerLabel["app.kubernetes.io/component"] == "server" { klog.Infof("Update a old ArgoCD Server Service, old: %v/%v, new: %v/%v", oldService.Namespace, oldService.Name, newService.Namespace, newService.Name) return true } if newArgocdServerLabel != nil && newArgocdServerLabel["app.kubernetes.io/part-of"] == "argocd" && newArgocdServerLabel["app.kubernetes.io/component"] == "server" { klog.Infof("Update a new ArgoCD Server Service, old: %v/%v, new: %v/%v", oldService.Namespace, oldService.Name, newService.Namespace, newService.Name) return true } klog.Infof("Not a ArgoCD Server service, old: %v/%v, new: %v/%v", oldService.Namespace, oldService.Name, newService.Namespace, newService.Name) return false }, CreateFunc: func(e event.CreateEvent) bool { ArgocdServerLabel := e.Object.GetLabels() if ArgocdServerLabel == nil { return false } else if ArgocdServerLabel["app.kubernetes.io/part-of"] != "argocd" || ArgocdServerLabel["app.kubernetes.io/component"] != "server" { return false } klog.Infof("Create a ArgoCD Server Service: %v/%v", e.Object.GetNamespace(), e.Object.GetName()) return true }, DeleteFunc: func(e event.DeleteEvent) bool { ArgocdServerLabel := e.Object.GetLabels() if ArgocdServerLabel == nil { return false } else if ArgocdServerLabel["app.kubernetes.io/part-of"] != "argocd" || ArgocdServerLabel["app.kubernetes.io/component"] != "server" { return false } klog.Infof("Delete a ArgoCD Server Service: %v/%v", e.Object.GetNamespace(), e.Object.GetName()) return true }, }
ArgocdServerPredicateFunc defines predicate function for cluster related watch
var ClusterPredicateFunc = predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { oldcl := e.ObjectOld.(*spokeClusterV1.ManagedCluster) newcl := e.ObjectNew.(*spokeClusterV1.ManagedCluster) if !reflect.DeepEqual(oldcl.DeletionTimestamp, newcl.DeletionTimestamp) { return true } if !reflect.DeepEqual(oldcl.Labels, newcl.Labels) { return true } oldcondMap := make(map[string]metav1.ConditionStatus) for _, cond := range oldcl.Status.Conditions { oldcondMap[cond.Type] = cond.Status } for _, cond := range newcl.Status.Conditions { oldcondst, ok := oldcondMap[cond.Type] if !ok || oldcondst != cond.Status { return true } delete(oldcondMap, cond.Type) } if len(oldcondMap) > 0 { return true } klog.V(1).Info("Out Cluster Predicate Func ", oldcl.Name, " with false possitive") return false }, }
ClusterPredicateFunc defines predicate function for cluster related watch, main purpose is to ignore heartbeat without change
var ManagedClusterSecretPredicateFunc = predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { _, isSecretInArgo := e.ObjectNew.GetLabels()[ArgocdClusterSecretLabel] if isSecretInArgo { klog.Infof("Managed cluster secret in ArgoCD namespace updated: %v/%v", e.ObjectNew.GetNamespace(), e.ObjectNew.GetName()) return false } return true }, CreateFunc: func(e event.CreateEvent) bool { _, isSecretInArgo := e.Object.GetLabels()[ArgocdClusterSecretLabel] if isSecretInArgo { klog.Infof("Managed cluster secret in ArgoCD namespace created: %v/%v", e.Object.GetNamespace(), e.Object.GetName()) return false } return true }, DeleteFunc: func(e event.DeleteEvent) bool { _, isSecretInArgo := e.Object.GetLabels()[ArgocdClusterSecretLabel] if isSecretInArgo { klog.Infof("Managed cluster secret in ArgoCD namespace deleted: %v/%v", e.Object.GetNamespace(), e.Object.GetName()) return true } return false }, }
ManagedClusterSecretPredicateFunc defines predicate function for managed cluster secrets watch
var PlacementDecisionPredicateFunc = predicate.Funcs{ CreateFunc: func(e event.CreateEvent) bool { decision, ok := e.Object.(*clusterv1alpha1.PlacementDecision) if !ok { return false } klog.Infof("placement decision created, %v/%v", decision.Namespace, decision.Name) return true }, DeleteFunc: func(e event.DeleteEvent) bool { decision, ok := e.Object.(*clusterv1alpha1.PlacementDecision) if !ok { return false } klog.Infof("placement decision deleted, %v/%v", decision.Namespace, decision.Name) return true }, UpdateFunc: func(e event.UpdateEvent) bool { oldDecision := e.ObjectOld.(*clusterv1alpha1.PlacementDecision) newDecision := e.ObjectNew.(*clusterv1alpha1.PlacementDecision) klog.Infof("placement decision updated, %v/%v", newDecision.Namespace, newDecision.Name) return !reflect.DeepEqual(oldDecision.Status, newDecision.Status) }, }
Functions ¶
func Base64StringDecode ¶
Base64StringDecode decode a base64 string
func CheckAndInstallCRD ¶
CheckAndInstallCRD checks if placementrule belongs to this cluster managed cluster annotation matches or no managed cluster annotation (local)
func ConvertLabels ¶
func ConvertLabels(labelSelector *metav1.LabelSelector) (labels.Selector, error)
ConvertLabels coverts label selector to lables.Selector
func DetectClusterRegistry ¶
DetectClusterRegistry - Detect the ACM cluster API service every 10 seconds. the controller will be exited when it is ready The controller will be auto restarted by the multicluster-operators-application deployment CR later.
func ExtractUserAndGroup ¶
func FilteClustersByIdentity ¶
func FilteClustersByIdentity(authClient kubernetes.Interface, object runtime.Object, clmap map[string]*spokeClusterV1.ManagedCluster) error
func GetManagedClusterNamespace ¶
GetManagedClusterNamespace return ACM secret namespace accoding to its secret name
func IfClusterAdmin ¶
func InstanceDeepCopy ¶
func InstanceDeepCopy(a, b interface{}) error
func IsReadyACMClusterRegistry ¶
IsReadyACMClusterRegistry check if ACM Cluster API service is ready or not.
func PlaceByGenericPlacmentFields ¶
func PlaceByGenericPlacmentFields(kubeclient client.Client, placement appv1alpha1.GenericPlacementFields, authclient kubernetes.Interface, object runtime.Object) (map[string]*spokeClusterV1.ManagedCluster, error)
PlaceByGenericPlacmentFields search with basic placement criteria Top priority: clusterNames, ignore selector Bottomline: Use label selector
func ToPlaceLocal ¶
func ToPlaceLocal(placement *appv1alpha1.Placement) bool
func ValidateK8sLabel ¶
ValidateK8sLabel returns a valid k8s label string by enforcing k8s label values rules as below
- Must consist of alphanumeric characters, '-', '_' or '.' No need to check this as the input string is the host name of the k8s api url
- Must be no more than 63 characters
- Must start and end with an alphanumeric character
Types ¶
type EventRecorder ¶
type EventRecorder struct {
record.EventRecorder
}
EventRecorder - record kubernetes event
func NewEventRecorder ¶
func NewEventRecorder(cfg *rest.Config, scheme *apiruntime.Scheme) (*EventRecorder, error)
NewEventRecorder - create new event recorder from rect config
func (*EventRecorder) RecordEvent ¶
func (rec *EventRecorder) RecordEvent(obj apiruntime.Object, reason, msg string, err error)
RecordEvent - record kuberentes event