Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1805172: pkg/verify/verifyconfigmap: Add klog logging #328

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/verify/verifyconfigmap/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package verifyconfigmap
import (
"context"
"fmt"
"sort"
"strings"
"sync"
"time"
Expand All @@ -14,6 +15,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/util/retry"
"k8s.io/klog"
)

// ReleaseLabelConfigMap is a label applied to a configmap inside the
Expand Down Expand Up @@ -53,8 +55,14 @@ func (s *Store) String() string {
// rememberMostRecentConfigMaps stores a set of config maps containing
// signatures.
func (s *Store) rememberMostRecentConfigMaps(last []corev1.ConfigMap) {
names := make([]string, 0, len(last))
for _, cm := range last {
names = append(names, cm.ObjectMeta.Name)
}
sort.Strings(names)
s.lock.Lock()
defer s.lock.Unlock()
klog.V(4).Infof("remember most recent signature config maps: %s", strings.Join(names, " "))
s.last = last
}

Expand All @@ -63,6 +71,7 @@ func (s *Store) rememberMostRecentConfigMaps(last []corev1.ConfigMap) {
func (s *Store) mostRecentConfigMaps() []corev1.ConfigMap {
s.lock.Lock()
defer s.lock.Unlock()
klog.V(4).Info("use cached most recent signature config maps")
return s.last
}

Expand Down Expand Up @@ -104,8 +113,10 @@ func (s *Store) DigestSignatures(ctx context.Context, digest string) ([][]byte,

var signatures [][]byte
for _, cm := range items {
klog.V(4).Infof("searching for %s in signature config map %s", prefix, cm.ObjectMeta.Name)
for k, v := range cm.BinaryData {
if strings.HasPrefix(k, prefix) {
klog.V(4).Infof("key %s from signature config map %s matches %s", k, cm.ObjectMeta.Name, digest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log prefix here in case it gets incorrectly generated? A better idea would be logging result in digestToKeyPrefix too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't get here if the digest string had incorrect format. Logging prefix is just for info.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm already logging the prefix a few lines up with searching for {prefix} in signature config map...?

signatures = append(signatures, v)
}
}
Expand All @@ -126,13 +137,15 @@ func (s *Store) Store(ctx context.Context, signaturesByDigest map[string][][]byt
},
BinaryData: make(map[string][]byte),
}
count := 0
for digest, signatures := range signaturesByDigest {
prefix, err := digestToKeyPrefix(digest)
if err != nil {
return err
}
for i := 0; i < len(signatures); i++ {
cm.BinaryData[fmt.Sprintf("%s-%d", prefix, i)] = signatures[i]
count += 1
}
}
return retry.OnError(
Expand All @@ -142,6 +155,9 @@ func (s *Store) Store(ctx context.Context, signaturesByDigest map[string][][]byt
existing, err := s.client.ConfigMaps(s.ns).Get(cm.Name, metav1.GetOptions{})
if errors.IsNotFound(err) {
_, err := s.client.ConfigMaps(s.ns).Create(cm)
if err != nil {
klog.V(4).Infof("create signature cache config map %s in namespace %s with %d signatures", cm.ObjectMeta.Name, s.ns, count)
}
return err
}
if err != nil {
Expand All @@ -151,6 +167,9 @@ func (s *Store) Store(ctx context.Context, signaturesByDigest map[string][][]byt
existing.BinaryData = cm.BinaryData
existing.Data = cm.Data
_, err = s.client.ConfigMaps(s.ns).Update(existing)
if err != nil {
klog.V(4).Infof("update signature cache config map %s in namespace %s with %d signatures", cm.ObjectMeta.Name, s.ns, count)
}
return err
},
)
Expand Down