@@ -18,8 +18,6 @@ package cachedresources
1818
1919import (
2020 "context"
21- "crypto/sha256"
22- "fmt"
2321 "time"
2422
2523 corev1 "k8s.io/api/core/v1"
@@ -41,7 +39,6 @@ import (
4139 "github.com/kcp-dev/kcp/pkg/tombstone"
4240 apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
4341 cachev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/cache/v1alpha1"
44- "github.com/kcp-dev/kcp/sdk/apis/third_party/conditions/util/conditions"
4542)
4643
4744type reconcileStatus int
@@ -63,11 +60,10 @@ func (c *Controller) reconcile(ctx context.Context, cluster logicalcluster.Name,
6360 reconcilers := []reconciler {
6461 & finalizer {},
6562 & identity {
66- ensureSecretNamespaceExists : c .ensureSecretNamespaceExists ,
67- getSecret : c .getSecret ,
68- createIdentitySecret : c .createIdentitySecret ,
69- updateOrVerifyIdentitySecretHash : c .updateOrVerifyIdentitySecretHash ,
70- secretNamespace : c .secretNamespace ,
63+ ensureSecretNamespaceExists : c .ensureSecretNamespaceExists ,
64+ getSecret : c .getSecret ,
65+ createIdentitySecret : c .createIdentitySecret ,
66+ secretNamespace : c .secretNamespace ,
7167 },
7268 & schemaSource {
7369 getLogicalCluster : c .getLogicalCluster ,
@@ -208,13 +204,13 @@ func (c *Controller) listSelectedCacheResources(ctx context.Context, cluster log
208204 return resources , nil
209205}
210206
211- func (c * Controller ) ensureSecretNamespaceExists (ctx context.Context , clusterName logicalcluster.Name ) {
207+ func (c * Controller ) ensureSecretNamespaceExists (ctx context.Context , clusterName logicalcluster.Name , defaultSecretNamespace string ) {
212208 logger := klog .FromContext (ctx )
213209 ctx = klog .NewContext (ctx , logger )
214- if _ , err := c .getNamespace (clusterName , c . secretNamespace ); errors .IsNotFound (err ) {
210+ if _ , err := c .getNamespace (clusterName , defaultSecretNamespace ); errors .IsNotFound (err ) {
215211 ns := & corev1.Namespace {
216212 ObjectMeta : metav1.ObjectMeta {
217- Name : c . secretNamespace ,
213+ Name : defaultSecretNamespace ,
218214 Annotations : map [string ]string {logicalcluster .AnnotationKey : clusterName .String ()},
219215 },
220216 }
@@ -226,8 +222,8 @@ func (c *Controller) ensureSecretNamespaceExists(ctx context.Context, clusterNam
226222 }
227223}
228224
229- func (c * Controller ) createIdentitySecret (ctx context.Context , clusterName logicalcluster.Path , apiExportName string ) error {
230- secret , err := GenerateIdentitySecret (ctx , c . secretNamespace , apiExportName )
225+ func (c * Controller ) createIdentitySecret (ctx context.Context , clusterName logicalcluster.Path , defaultSecretNamespace , cachedResourceName string ) error {
226+ secret , err := GenerateIdentitySecret (ctx , defaultSecretNamespace , cachedResourceName )
231227 if err != nil {
232228 return err
233229 }
@@ -239,42 +235,6 @@ func (c *Controller) createIdentitySecret(ctx context.Context, clusterName logic
239235 return c .createSecret (ctx , clusterName , secret )
240236}
241237
242- func (c * Controller ) updateOrVerifyIdentitySecretHash (ctx context.Context , clusterName logicalcluster.Name , cachedResource * cachev1alpha1.CachedResource ) error {
243- secret , err := c .getSecret (ctx , clusterName , c .secretNamespace , cachedResource .Name )
244- if err != nil {
245- return err
246- }
247-
248- hash , err := IdentityHash (secret )
249- if err != nil {
250- return err
251- }
252-
253- if cachedResource .Status .IdentityHash == "" {
254- cachedResource .Status .IdentityHash = hash
255- }
256-
257- if cachedResource .Status .IdentityHash != hash {
258- return fmt .Errorf ("hash mismatch: identity secret hash %q must match status.identityHash %q" , hash , cachedResource .Status .IdentityHash )
259- }
260-
261- conditions .MarkTrue (cachedResource , cachev1alpha1 .CachedResourceIdentityValid )
262-
263- return nil
264- }
265-
266- // TODO: This is copy from apiexport controller. We should move it to a shared location.
267- func IdentityHash (secret * corev1.Secret ) (string , error ) {
268- key := secret .Data [apisv1alpha1 .SecretKeyAPIExportIdentity ]
269- if len (key ) == 0 {
270- return "" , fmt .Errorf ("secret is missing data.%s" , apisv1alpha1 .SecretKeyAPIExportIdentity )
271- }
272-
273- hashBytes := sha256 .Sum256 (key )
274- hash := fmt .Sprintf ("%x" , hashBytes )
275- return hash , nil
276- }
277-
278238// TODO: This is copy from apiexport controller. We should move it to a shared location.
279239func GenerateIdentitySecret (ctx context.Context , ns string , name string ) (* corev1.Secret , error ) {
280240 logger := klog .FromContext (ctx )
0 commit comments