Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add watch to credential
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed May 27, 2022
1 parent 0ee538d commit 3a28b49
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/server/registry/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
apiv1 "github.com/acorn-io/acorn/pkg/apis/api.acorn.io/v1"
"github.com/acorn-io/acorn/pkg/labels"
"github.com/acorn-io/acorn/pkg/tables"
"github.com/acorn-io/acorn/pkg/watcher"
corev1 "k8s.io/api/core/v1"
apierror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
klabels "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -221,3 +223,27 @@ func (s *Storage) List(ctx context.Context, options *internalversion.ListOptions

return result, nil
}

func (s *Storage) Watch(ctx context.Context, options *internalversion.ListOptions) (watch.Interface, error) {
ns, _ := request.NamespaceFrom(ctx)

opts := watcher.ListOptions(ns, options)
opts.FieldSelector = nil
opts.Raw.FieldSelector = ""
opts.LabelSelector = klabels.SelectorFromSet(map[string]string{
labels.AcornCredential: "true",
labels.AcornManaged: "true",
})

w, err := s.client.Watch(ctx, &corev1.SecretList{}, opts)
if err != nil {
return nil, err
}

return watcher.Transform(w, func(object runtime.Object) []runtime.Object {
sec := object.(*corev1.Secret)
return []runtime.Object{
secretToCredential(*sec),
}
}), nil
}

0 comments on commit 3a28b49

Please sign in to comment.