Skip to content

Commit

Permalink
Rename createdAt to creationTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
benashz committed Jun 11, 2024
1 parent 48da7ad commit fe69075
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions api/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ type VaultClientMeta struct {
// ID is the Vault ID of the authenticated client. The ID should never contain
// any sensitive information.
ID string `json:"id,omitempty"`
// CreatedAt is the time the client was created.
CreatedAt metav1.Time `json:"createdAt,omitempty"`
// CreationTimestamp is the time the client was created.
CreationTimestamp metav1.Time `json:"creationTimestamp,omitempty"`
}
2 changes: 1 addition & 1 deletion api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chart/crds/secrets.hashicorp.com_vaultdynamicsecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ spec:
description: CacheKey is the unique key used to identify the client
cache.
type: string
createdAt:
description: CreatedAt is the time the client was created.
creationTimestamp:
description: CreationTimestamp is the time the client was created.
format: date-time
type: string
id:
Expand Down
4 changes: 2 additions & 2 deletions chart/crds/secrets.hashicorp.com_vaultpkisecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ spec:
description: CacheKey is the unique key used to identify the client
cache.
type: string
createdAt:
description: CreatedAt is the time the client was created.
creationTimestamp:
description: CreationTimestamp is the time the client was created.
format: date-time
type: string
id:
Expand Down
4 changes: 2 additions & 2 deletions chart/crds/secrets.hashicorp.com_vaultstaticsecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ spec:
description: CacheKey is the unique key used to identify the client
cache.
type: string
createdAt:
description: CreatedAt is the time the client was created.
creationTimestamp:
description: CreationTimestamp is the time the client was created.
format: date-time
type: string
id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ spec:
description: CacheKey is the unique key used to identify the client
cache.
type: string
createdAt:
description: CreatedAt is the time the client was created.
creationTimestamp:
description: CreationTimestamp is the time the client was created.
format: date-time
type: string
id:
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/secrets.hashicorp.com_vaultpkisecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ spec:
description: CacheKey is the unique key used to identify the client
cache.
type: string
createdAt:
description: CreatedAt is the time the client was created.
creationTimestamp:
description: CreationTimestamp is the time the client was created.
format: date-time
type: string
id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ spec:
description: CacheKey is the unique key used to identify the client
cache.
type: string
createdAt:
description: CreatedAt is the time the client was created.
creationTimestamp:
description: CreationTimestamp is the time the client was created.
format: date-time
type: string
id:
Expand Down
2 changes: 1 addition & 1 deletion controllers/vaultdynamicsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
// update the VaultClientMeta in the resource's status.
o.Status.VaultClientMeta.CacheKey = clientCacheKey.String()
o.Status.VaultClientMeta.ID = c.ID()
o.Status.VaultClientMeta.CreatedAt = metav1.NewTime(c.Stat().CreatedAt())
o.Status.VaultClientMeta.CreationTimestamp = metav1.NewTime(c.Stat().CreationTimestamp())

var syncReason string
// doSync indicates that the controller should perform the secret sync,
Expand Down
2 changes: 1 addition & 1 deletion controllers/vaultpkisecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (r *VaultPKISecretReconciler) Reconcile(ctx context.Context, req ctrl.Reque
clientCacheKey, _ := c.GetCacheKey()
o.Status.VaultClientMeta.CacheKey = clientCacheKey.String()
o.Status.VaultClientMeta.ID = c.ID()
o.Status.VaultClientMeta.CreatedAt = metav1.NewTime(c.Stat().CreatedAt())
o.Status.VaultClientMeta.CreationTimestamp = metav1.NewTime(c.Stat().CreationTimestamp())

resp, err := c.Write(ctx, vault.NewWriteRequest(path, o.GetIssuerAPIData()))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/vaultstaticsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *VaultStaticSecretReconciler) Reconcile(ctx context.Context, req ctrl.Re
clientCacheKey, _ := c.GetCacheKey()
o.Status.VaultClientMeta.CacheKey = clientCacheKey.String()
o.Status.VaultClientMeta.ID = c.ID()
o.Status.VaultClientMeta.CreatedAt = metav1.NewTime(c.Stat().CreatedAt())
o.Status.VaultClientMeta.CreationTimestamp = metav1.NewTime(c.Stat().CreationTimestamp())

resp, err := c.Read(ctx, kvReq)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docs/api/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ _Appears in:_
| --- | --- | --- | --- |
| `cacheKey` _string_ | CacheKey is the unique key used to identify the client cache. | | |
| `id` _string_ | ID is the Vault ID of the authenticated client. The ID should never contain<br />any sensitive information. | | |
| `createdAt` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | CreatedAt is the time the client was created. | | |
| `creationTimestamp` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | CreationTimestamp is the time the client was created. | | |


#### VaultConnection
Expand Down
16 changes: 8 additions & 8 deletions internal/vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

type ClientStat interface {
Age() time.Duration
CreatedAt() time.Time
CreationTimestamp() time.Time
Reset()
RefCount() int
IncRefCount()
Expand All @@ -38,32 +38,32 @@ type ClientStat interface {
var _ ClientStat = (*clientStat)(nil)

type clientStat struct {
// createdAt is the time the client was created.
createdAt time.Time
// creationTimestamp is the time the client was created.
creationTimestamp time.Time
// refCount is the number of references to the client.
refCount int
mu sync.RWMutex
}

// CreatedAt returns the time the client was created.
func (m *clientStat) CreatedAt() time.Time {
// CreationTimestamp returns the time the client was created.
func (m *clientStat) CreationTimestamp() time.Time {
m.mu.RLock()
defer m.mu.RUnlock()
return m.createdAt
return m.creationTimestamp
}

// Age returns the duration since the client was created.
func (m *clientStat) Age() time.Duration {
m.mu.RLock()
defer m.mu.RUnlock()
return time.Since(m.createdAt)
return time.Since(m.creationTimestamp)
}

// Reset the client's creation time to the current time.
func (m *clientStat) Reset() {
m.mu.Lock()
defer m.mu.Unlock()
m.createdAt = time.Now()
m.creationTimestamp = time.Now()
m.refCount = 0
}

Expand Down
4 changes: 2 additions & 2 deletions internal/vault/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func (m *cachingClientFactory) Get(ctx context.Context, client ctrlclient.Client
decrementReason = "cacheKeyChange"
incrementReason = "cacheKeyChange"
default:
if c, ok := m.cache.Get(cacheKey); ok && c.Stat().CreatedAt().Unix() != lastVaultClientMeta.CreatedAt.Unix() {
if c, ok := m.cache.Get(cacheKey); ok && c.Stat().CreationTimestamp().Unix() != lastVaultClientMeta.CreationTimestamp.Unix() {
incrementReason = "createdAtChange"
}
}
Expand All @@ -461,7 +461,7 @@ func (m *cachingClientFactory) Get(ctx context.Context, client ctrlclient.Client
c.Stat().IncRefCount()
logger.Info("Increment ref count",
"lastVaultClientMeta", lastVaultClientMeta, "refCount", c.Stat().RefCount(),
"createdAt", c.Stat().CreatedAt(),
"creationTimestamp", c.Stat().CreationTimestamp(),
"reason", incrementReason,
)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/vault/client_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func Test_cachingClientFactory_pruneOrphanClients(t *testing.T) {
c.cache.Add(k.key, &stubClient{
cacheKey: k.key,
clientStat: &clientStat{
createdAt: time.Now().Add(k.creationTimeOffset),
creationTimestamp: time.Now().Add(k.creationTimeOffset),
},
})
}
Expand Down

0 comments on commit fe69075

Please sign in to comment.