Skip to content

Commit 04ee659

Browse files
amirejazclaude
andcommitted
Update PR5 converter for CacheFallbackTTL string type
CIMDRunConfig.CacheFallbackTTL changed from time.Duration to string in PR3. The operator converter now passes the string through unchanged; parsing to time.Duration happens in resolveCIMDConfig in the runner, after CIMDRunConfig.Validate() has already confirmed the format. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 1be3221 commit 04ee659

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

cmd/thv-operator/pkg/controllerutil/authserver.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"fmt"
99
"strings"
10-
"time"
1110

1211
corev1 "k8s.io/api/core/v1"
1312
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -583,20 +582,14 @@ func BuildAuthServerRunConfig(
583582
}
584583
config.Storage = storageCfg
585584

586-
// Build CIMD configuration
585+
// Build CIMD configuration. CacheFallbackTTL is passed as-is (string);
586+
// resolveCIMDConfig in the runner parses it to time.Duration at startup.
587587
if authConfig.CIMD != nil && authConfig.CIMD.Enabled {
588-
cimdCfg := &authserver.CIMDRunConfig{
589-
Enabled: authConfig.CIMD.Enabled,
590-
CacheMaxSize: authConfig.CIMD.CacheMaxSize,
588+
config.CIMD = &authserver.CIMDRunConfig{
589+
Enabled: authConfig.CIMD.Enabled,
590+
CacheMaxSize: authConfig.CIMD.CacheMaxSize,
591+
CacheFallbackTTL: authConfig.CIMD.CacheFallbackTTL,
591592
}
592-
if authConfig.CIMD.CacheFallbackTTL != "" {
593-
ttl, err := time.ParseDuration(authConfig.CIMD.CacheFallbackTTL)
594-
if err != nil {
595-
return nil, fmt.Errorf("cimd.cacheFallbackTtl: %w", err)
596-
}
597-
cimdCfg.CacheFallbackTTL = ttl
598-
}
599-
config.CIMD = cimdCfg
600593
}
601594

602595
return config, nil

cmd/thv-operator/pkg/controllerutil/authserver_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"strings"
1010
"testing"
11-
"time"
1211

1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/require"
@@ -2709,7 +2708,7 @@ func TestBuildAuthServerRunConfig_CIMD(t *testing.T) {
27092708
t.Helper()
27102709
assert.True(t, got.Enabled)
27112710
assert.Equal(t, 512, got.CacheMaxSize)
2712-
assert.Equal(t, 10*time.Minute, got.CacheFallbackTTL)
2711+
assert.Equal(t, "10m", got.CacheFallbackTTL)
27132712
},
27142713
},
27152714
{
@@ -2726,13 +2725,18 @@ func TestBuildAuthServerRunConfig_CIMD(t *testing.T) {
27262725
},
27272726
},
27282727
{
2729-
name: "invalid CacheFallbackTTL returns parse error",
2728+
name: "invalid CacheFallbackTTL passes through to runner for validation",
27302729
cimd: &mcpv1beta1.EmbeddedAuthServerCIMDConfig{
27312730
Enabled: true,
27322731
CacheFallbackTTL: "not-a-duration",
27332732
},
2734-
wantErr: true,
2735-
errContains: "cimd.cacheFallbackTtl",
2733+
wantCIMD: true,
2734+
checkFunc: func(t *testing.T, got *authserver.CIMDRunConfig) {
2735+
t.Helper()
2736+
// The converter passes the string through; parse errors are caught
2737+
// by CIMDRunConfig.Validate() or resolveCIMDConfig in the runner.
2738+
assert.Equal(t, "not-a-duration", got.CacheFallbackTTL)
2739+
},
27362740
},
27372741
}
27382742

0 commit comments

Comments
 (0)