Skip to content

Commit

Permalink
managed by
Browse files Browse the repository at this point in the history
  • Loading branch information
friedrichwilken committed Jan 3, 2024
1 parent 116ebda commit ab5bef0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 10 additions & 10 deletions internal/controller/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ func New(config *rest.Config, options cache.Options) (cache.Cache, error) {

func applySelectors(options cache.Options) cache.Options {
// The only objects we allow are the ones with the 'created-by: nats-manager' label applied.
createdByNATSManager := fromLabelSelector(label.SelectorCreatedByNATS())
labelSelector := fromLabelSelector(label.SelectorManagedByNATS())

// Apply the label selector to all relevant objects.
options.ByObject = map[client.Object]cache.ByObject{
&appsv1.Deployment{}: createdByNATSManager,
&autoscalingv1.HorizontalPodAutoscaler{}: createdByNATSManager,
&corev1.ServiceAccount{}: createdByNATSManager,
&rbacv1.ClusterRole{}: createdByNATSManager,
&rbacv1.ClusterRoleBinding{}: createdByNATSManager,
&policyv1.PodDisruptionBudget{}: createdByNATSManager,
&appsv1.Deployment{}: labelSelector,
&autoscalingv1.HorizontalPodAutoscaler{}: labelSelector,
&corev1.ServiceAccount{}: labelSelector,
&rbacv1.ClusterRole{}: labelSelector,
&rbacv1.ClusterRoleBinding{}: labelSelector,
&policyv1.PodDisruptionBudget{}: labelSelector,

&corev1.ConfigMap{}: createdByNATSManager,
&corev1.Secret{}: createdByNATSManager,
&corev1.Service{}: createdByNATSManager,
&corev1.ConfigMap{}: labelSelector,
&corev1.Secret{}: labelSelector,
&corev1.Service{}: labelSelector,
}
return options
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ func SelectorInstanceNATS() labels.Selector {
func SelectorCreatedByNATS() labels.Selector {
return labels.SelectorFromSet(map[string]string{KeyCreatedBy: ValueNATSManager})
}

// TODO
func SelectorManagedByNATS() labels.Selector {
return labels.SelectorFromSet(map[string]string{KeyManagedBy: ValueNATSManager})
}

0 comments on commit ab5bef0

Please sign in to comment.