@@ -3,6 +3,7 @@ package verifyconfigmap
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "sort"
6
7
"strings"
7
8
"sync"
8
9
"time"
@@ -14,6 +15,7 @@ import (
14
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
16
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
16
17
"k8s.io/client-go/util/retry"
18
+ "k8s.io/klog"
17
19
)
18
20
19
21
// ReleaseLabelConfigMap is a label applied to a configmap inside the
@@ -53,8 +55,14 @@ func (s *Store) String() string {
53
55
// rememberMostRecentConfigMaps stores a set of config maps containing
54
56
// signatures.
55
57
func (s * Store ) rememberMostRecentConfigMaps (last []corev1.ConfigMap ) {
58
+ names := make ([]string , 0 , len (last ))
59
+ for _ , cm := range last {
60
+ names = append (names , cm .ObjectMeta .Name )
61
+ }
62
+ sort .Strings (names )
56
63
s .lock .Lock ()
57
64
defer s .lock .Unlock ()
65
+ klog .V (4 ).Infof ("remember most recent signature config maps: %s" , strings .Join (names , " " ))
58
66
s .last = last
59
67
}
60
68
@@ -63,6 +71,7 @@ func (s *Store) rememberMostRecentConfigMaps(last []corev1.ConfigMap) {
63
71
func (s * Store ) mostRecentConfigMaps () []corev1.ConfigMap {
64
72
s .lock .Lock ()
65
73
defer s .lock .Unlock ()
74
+ klog .V (4 ).Info ("use cached most recent signature config maps" )
66
75
return s .last
67
76
}
68
77
@@ -104,8 +113,10 @@ func (s *Store) DigestSignatures(ctx context.Context, digest string) ([][]byte,
104
113
105
114
var signatures [][]byte
106
115
for _ , cm := range items {
116
+ klog .V (4 ).Infof ("searching for %s in signature config map %s" , prefix , cm .ObjectMeta .Name )
107
117
for k , v := range cm .BinaryData {
108
118
if strings .HasPrefix (k , prefix ) {
119
+ klog .V (4 ).Infof ("key %s from signature config map %s matches %s" , k , cm .ObjectMeta .Name , digest )
109
120
signatures = append (signatures , v )
110
121
}
111
122
}
@@ -126,13 +137,15 @@ func (s *Store) Store(ctx context.Context, signaturesByDigest map[string][][]byt
126
137
},
127
138
BinaryData : make (map [string ][]byte ),
128
139
}
140
+ count := 0
129
141
for digest , signatures := range signaturesByDigest {
130
142
prefix , err := digestToKeyPrefix (digest )
131
143
if err != nil {
132
144
return err
133
145
}
134
146
for i := 0 ; i < len (signatures ); i ++ {
135
147
cm .BinaryData [fmt .Sprintf ("%s-%d" , prefix , i )] = signatures [i ]
148
+ count += 1
136
149
}
137
150
}
138
151
return retry .OnError (
@@ -142,6 +155,9 @@ func (s *Store) Store(ctx context.Context, signaturesByDigest map[string][][]byt
142
155
existing , err := s .client .ConfigMaps (s .ns ).Get (cm .Name , metav1.GetOptions {})
143
156
if errors .IsNotFound (err ) {
144
157
_ , err := s .client .ConfigMaps (s .ns ).Create (cm )
158
+ if err != nil {
159
+ klog .V (4 ).Infof ("create signature cache config map %s in namespace %s with %d signatures" , cm .ObjectMeta .Name , s .ns , count )
160
+ }
145
161
return err
146
162
}
147
163
if err != nil {
@@ -151,6 +167,9 @@ func (s *Store) Store(ctx context.Context, signaturesByDigest map[string][][]byt
151
167
existing .BinaryData = cm .BinaryData
152
168
existing .Data = cm .Data
153
169
_ , err = s .client .ConfigMaps (s .ns ).Update (existing )
170
+ if err != nil {
171
+ klog .V (4 ).Infof ("update signature cache config map %s in namespace %s with %d signatures" , cm .ObjectMeta .Name , s .ns , count )
172
+ }
154
173
return err
155
174
},
156
175
)
0 commit comments