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

feat: Istio Gateway Secret CA Cert Bundling #2226

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
0e876d9
test: Watcher Zero Downtime E2E Test
LeelaChacha Jan 31, 2025
22c8d56
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Jan 31, 2025
0f34f26
fix: Get fresh Kyma before updating module
LeelaChacha Jan 31, 2025
e29cacf
fix: Get fresh Kyma before updating module
LeelaChacha Jan 31, 2025
9e9ac30
fix: Use controller runtime client instead of kubectl
LeelaChacha Jan 31, 2025
ee089e8
WIP: Test legacy flag
LeelaChacha Feb 3, 2025
d36cc02
WIP: Fix Test for legacy flag
LeelaChacha Feb 3, 2025
5b1d213
WIP: Fix Test for legacy flag
LeelaChacha Feb 4, 2025
ceb1a88
WIP: Fix Test for legacy flag
LeelaChacha Feb 4, 2025
102c720
WIP: Fix Test for legacy flag
LeelaChacha Feb 4, 2025
991fc5a
WIP: Fix Test for legacy flag
LeelaChacha Feb 4, 2025
9faf525
WIP: Fix Test for legacy flag
LeelaChacha Feb 4, 2025
2cd6d11
feat: Bundle CAs in Istio Gateway Secret
LeelaChacha Feb 6, 2025
25e5e37
feat: Introduce Istio Gateway Secret Requeue Intervals
LeelaChacha Feb 6, 2025
ba63ce5
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 6, 2025
c9b9a88
fix: Invalid Github Action Step
LeelaChacha Feb 6, 2025
bb3ed6a
fix(unit-test-coverage.yaml): Rename Package
LeelaChacha Feb 6, 2025
a357a41
fix(unit-test-coverage.yaml): Rename Package
LeelaChacha Feb 6, 2025
705c9b9
fix(unit-test-coverage.yaml): Rename Package
LeelaChacha Feb 6, 2025
de388c9
fix(unit-test-coverage.yaml): Rename Package
LeelaChacha Feb 6, 2025
7bcf0d2
chore: Update covergae
LeelaChacha Feb 6, 2025
8e733c0
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 10, 2025
afdb6c5
test: Unit Test for CA Bundle Handler
LeelaChacha Feb 10, 2025
4619234
fix: Use New Metrics Methods
LeelaChacha Feb 10, 2025
4695d4b
refactor: Lint
LeelaChacha Feb 10, 2025
988c170
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 10, 2025
3e15f64
chore: Decrease test gateway secret requeue interval
LeelaChacha Feb 10, 2025
2b6b0f5
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 10, 2025
ed2018a
fix: e2e zero downtime cert switching time
LeelaChacha Feb 10, 2025
585c225
fix: e2e zero downtime cert switching time
LeelaChacha Feb 10, 2025
f3f7ba7
fix: e2e zero downtime cert switching time
LeelaChacha Feb 10, 2025
cf46a57
fix: e2e zero downtime cert switching time
LeelaChacha Feb 10, 2025
b722ac0
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 11, 2025
5c911b4
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 12, 2025
f18a244
chore: Adjust Istio Gateway Requeue Interval for E2E
LeelaChacha Feb 12, 2025
ededa4b
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 12, 2025
5f4c1fc
chore: Adjust Istio Gateway Requeue Interval for E2E
LeelaChacha Feb 12, 2025
b9c07b8
chore: Adjust Istio Gateway Requeue Interval for E2E
LeelaChacha Feb 12, 2025
31a159d
chore: Adjust Istio Gateway Requeue Interval for E2E
LeelaChacha Feb 12, 2025
570ca9b
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 13, 2025
a073120
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 14, 2025
2bc21f6
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 17, 2025
78d4cd1
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 18, 2025
fed6094
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 18, 2025
5b6ddcd
feat: Bootstrap Legacy Gateway Secret for Migration
LeelaChacha Feb 19, 2025
2a837f7
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 19, 2025
7510fc3
chore: Lint
LeelaChacha Feb 19, 2025
a9b0d6e
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 19, 2025
c0aaa14
refactor: unnecessary receiver method
LeelaChacha Feb 19, 2025
0b7f65e
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 20, 2025
d246cd4
refactor: better legacy secret detection
LeelaChacha Feb 20, 2025
1905d96
chore: adjust e2e arguments
LeelaChacha Feb 20, 2025
f7d8d40
Merge branch 'main' into feature/#1506-istio-gateway-secret-ca-bundling
LeelaChacha Feb 20, 2025
3295feb
refactor: better certificate validation, append() in bundleCaCrt()
LeelaChacha Feb 21, 2025
716ef51
refactor: use slices.Clone() instead of append()
LeelaChacha Feb 21, 2025
0cbf915
chore: Remove Redundant NPE Handling
LeelaChacha Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions .github/actions/deploy-lifecycle-manager-e2e/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,28 @@ runs:
cat requeue-interval-patch.yaml
kustomize edit add patch --path requeue-interval-patch.yaml --kind Deployment
popd
- name: Patch KLM deployment for watcher zero downtime
if: ${{matrix.e2e-test == 'watcher-zero-downtime'}}
working-directory: lifecycle-manager
shell: bash
run: |
pushd config/watcher_local_test
echo \
"- op: replace
path: /spec/template/spec/containers/0/args/16
value: --kyma-requeue-success-interval=10s
- op: add
path: /spec/template/spec/containers/0/args/-
value: --istio-gateway-cert-switch-before-expiration-time=58m30s
- op: add
path: /spec/template/spec/containers/0/args/-
value: --istio-gateway-secret-requeue-success-interval=6s" >> requeue-interval-patch.yaml
cat requeue-interval-patch.yaml
kustomize edit add patch --path requeue-interval-patch.yaml --kind Deployment
popd
- name: Patch CA certificate renewBefore
if: ${{matrix.e2e-test == 'ca-certificate-rotation' ||
matrix.e2e-test == 'istio-gateway-secret-rotation'}}
if: ${{matrix.e2e-test == 'legacy-istio-gateway-secret-rotation' ||
matrix.e2e-test == 'watcher-zero-downtime'}}
working-directory: lifecycle-manager
shell: bash
run: |
Expand All @@ -97,6 +116,19 @@ runs:
cat certificate_renewal.yaml
kustomize edit add patch --path certificate_renewal.yaml --kind Certificate --group cert-manager.io --version v1 --name watcher-serving
popd
- name: Use legacy istio gateway secret rotation strategy
if: ${{matrix.e2e-test == 'legacy-istio-gateway-secret-rotation'}}
working-directory: lifecycle-manager
shell: bash
run: |
pushd config/watcher_local_test
echo \
"- op: add
path: /spec/template/spec/containers/0/args/-
value: --legacy-strategy-for-istio-gateway-secret=true" >> legacy-secret-rotation.yaml
cat legacy-secret-rotation.yaml
kustomize edit add patch --path legacy-secret-rotation.yaml --kind Deployment
popd
- name: Create and use maintenance window policy
if: ${{matrix.e2e-test == 'maintenance-windows' ||
matrix.e2e-test == 'maintenance-windows-initial-installation' ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ runs:
- name: Create and apply Template Operator ModuleTemplate from the latest release
working-directory: template-operator
if: ${{ matrix.e2e-test != 'mandatory-module' &&
matrix.e2e-test != 'mandatory-module-metrics'
matrix.e2e-test != 'mandatory-module-metrics' &&
matrix.e2e-test != 'watcher-zero-downtime'
}}
shell: bash
run: |
Expand All @@ -32,7 +33,8 @@ runs:
- name: Create and apply Template Operator ModuleTemplate with ModuleDeploymentNameInOlderVersion
working-directory: template-operator
if: ${{ matrix.e2e-test != 'mandatory-module' &&
matrix.e2e-test != 'mandatory-module-metrics'
matrix.e2e-test != 'mandatory-module-metrics' &&
matrix.e2e-test != 'watcher-zero-downtime'
}}
shell: bash
run: |
Expand All @@ -42,7 +44,8 @@ runs:
- name: Create and apply Template Operator ModuleTemplate with ModuleDeploymentNameInNewerVersion
working-directory: template-operator
if: ${{ matrix.e2e-test != 'mandatory-module' &&
matrix.e2e-test != 'mandatory-module-metrics'
matrix.e2e-test != 'mandatory-module-metrics' &&
matrix.e2e-test != 'watcher-zero-downtime'
}}
shell: bash
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-e2e-with-modulereleasemeta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ jobs:
- modulereleasemeta-module-upgrade-new-version
- unmanage-module
- skip-manifest-reconciliation
- ca-certificate-rotation
- istio-gateway-secret-rotation
- legacy-istio-gateway-secret-rotation
- self-signed-certificate-rotation
- mandatory-module
- mandatory-module-metrics
Expand All @@ -70,6 +69,7 @@ jobs:
- maintenance-windows
- maintenance-windows-initial-installation
- maintenance-windows-skip
- watcher-zero-downtime

runs-on: ubuntu-latest
timeout-minutes: 20
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ jobs:
- unmanage-module
- module-install-by-version
- skip-manifest-reconciliation
- ca-certificate-rotation
- istio-gateway-secret-rotation
- legacy-istio-gateway-secret-rotation
- self-signed-certificate-rotation
- mandatory-module-with-old-naming-pattern
- mandatory-module-metrics-with-old-naming-pattern
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ linters-settings:
alias: watcherctrl
- pkg: github.com/kyma-project/lifecycle-manager/internal/gatewaysecret/client
alias: gatewaysecretclient
- pkg: github.com/kyma-project/lifecycle-manager/internal/gatewaysecret/handler
alias: gatewaysecrethandler
ireturn:
allow:
- anon
Expand Down
1 change: 0 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
"module-upgrade-new-version",
"unmanage-module",
"skip-manifest-reconciliation",
"ca-certificate-rotation",
"self-signed-certificate-rotation",
"mandatory-module",
"mandatory-module-metrics",
Expand Down
12 changes: 8 additions & 4 deletions internal/controller/istiogatewaysecret/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/kyma-project/lifecycle-manager/pkg/log"
"github.com/kyma-project/lifecycle-manager/pkg/queue"
)

var ErrSecretNotFound = errors.New("root secret not found")
Expand All @@ -25,12 +26,14 @@ type (
type Reconciler struct {
getRootSecret GetterFunc
handler Handler
intervals queue.RequeueIntervals
}

func NewReconciler(getSecretFunc GetterFunc, handler Handler) *Reconciler {
func NewReconciler(getSecretFunc GetterFunc, handler Handler, intervals queue.RequeueIntervals) *Reconciler {
return &Reconciler{
getRootSecret: getSecretFunc,
handler: handler,
intervals: intervals,
}
}

Expand All @@ -42,13 +45,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, fmt.Errorf("failed to get istio gateway root secret: %w", err)
}
if rootSecret == nil {
return ctrl.Result{}, ErrSecretNotFound
return ctrl.Result{Requeue: true, RequeueAfter: r.intervals.Error}, ErrSecretNotFound
}

err = r.handler.ManageGatewaySecret(ctx, rootSecret)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to manage gateway secret: %w", err)
return ctrl.Result{Requeue: true, RequeueAfter: r.intervals.Error},
fmt.Errorf("failed to manage gateway secret: %w", err)
}

return ctrl.Result{}, nil
return ctrl.Result{Requeue: true, RequeueAfter: r.intervals.Success}, nil
}
11 changes: 6 additions & 5 deletions internal/controller/istiogatewaysecret/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

"github.com/kyma-project/lifecycle-manager/internal/controller/istiogatewaysecret"
"github.com/kyma-project/lifecycle-manager/pkg/queue"
)

func TestReconcile_WhenGetSecretFuncReturnsError_ReturnError(t *testing.T) {
Expand All @@ -20,7 +21,7 @@ func TestReconcile_WhenGetSecretFuncReturnsError_ReturnError(t *testing.T) {
return nil, errors.New("some-error")
}
mockHandler := &mockHandler{}
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, mockHandler)
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, mockHandler, queue.RequeueIntervals{})

// ACT
_, err := reconciler.Reconcile(context.TODO(), ctrl.Request{})
Expand All @@ -36,7 +37,7 @@ func TestReconcile_WhenGetSecretFuncReturnsNoErrorAndSecretIsNil_ReturnError(t *
return nil, nil
}
mockHandler := &mockHandler{}
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, mockHandler)
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, mockHandler, queue.RequeueIntervals{})

// ACT
_, err := reconciler.Reconcile(context.TODO(), ctrl.Request{})
Expand All @@ -56,7 +57,7 @@ func TestReconcile_WhenGetSecretFuncIsCalled_IsCalledWithRequestNamespacedName(t
assert.Equal(t, request.Name, name.Name)
return nil, nil
}
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, &mockHandler{})
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, &mockHandler{}, queue.RequeueIntervals{})

// ACT
// ASSERT
Expand All @@ -70,7 +71,7 @@ func TestReconcile_WhenGetSecretFuncReturnsSecret_HandlerManageGatewaySecretIsCa
return secret, nil
}
mockHandler := &mockHandler{}
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, mockHandler)
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, mockHandler, queue.RequeueIntervals{})

// ACT
_, err := reconciler.Reconcile(context.TODO(), ctrl.Request{})
Expand All @@ -87,7 +88,7 @@ func TestReconcile_WhenHandlerManageGatewaySecretReturnsError_ReturnError(t *tes
return secret, nil
}
mockHandler := &mockHandler{err: errors.New("some-error")}
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, mockHandler)
reconciler := istiogatewaysecret.NewReconciler(stubGetterFunc, mockHandler, queue.RequeueIntervals{})

// ACT
_, err := reconciler.Reconcile(context.TODO(), ctrl.Request{})
Expand Down
31 changes: 23 additions & 8 deletions internal/controller/istiogatewaysecret/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,42 @@ import (

"github.com/kyma-project/lifecycle-manager/api/shared"
"github.com/kyma-project/lifecycle-manager/internal/gatewaysecret"
"github.com/kyma-project/lifecycle-manager/internal/gatewaysecret/cabundle"
gatewaysecretclient "github.com/kyma-project/lifecycle-manager/internal/gatewaysecret/client"
"github.com/kyma-project/lifecycle-manager/internal/gatewaysecret/legacy"
"github.com/kyma-project/lifecycle-manager/internal/pkg/flags"
"github.com/kyma-project/lifecycle-manager/pkg/queue"
)

const (
controllerName = "istio-controller"
kcpRootSecretName = "klm-watcher"
)

var errCouldNotGetLastModifiedAt = errors.New("getting lastModifiedAt time failed")
var errCouldNotGetTimeFromAnnotation = errors.New("getting time from annotation failed")

func SetupReconciler(mgr ctrl.Manager, flagVar *flags.FlagVar, options ctrlruntime.Options) error {
options.MaxConcurrentReconciles = flagVar.MaxConcurrentWatcherReconciles

clnt := gatewaysecretclient.NewGatewaySecretRotationClient(mgr.GetConfig())
var parseLastModifiedFunc gatewaysecret.TimeParserFunc = func(secret *apicorev1.Secret) (time.Time, error) {
if gwSecretLastModifiedAtValue, ok := secret.Annotations[shared.LastModifiedAtAnnotation]; ok {
if gwSecretLastModifiedAt, err := time.Parse(time.RFC3339, gwSecretLastModifiedAtValue); err == nil {
return gwSecretLastModifiedAt, nil
var parseLastModifiedFunc gatewaysecret.TimeParserFunc = func(secret *apicorev1.Secret,
annotation string,
) (time.Time, error) {
if strValue, ok := secret.Annotations[annotation]; ok {
if time, err := time.Parse(time.RFC3339, strValue); err == nil {
return time, nil
}
}
return time.Time{}, errCouldNotGetLastModifiedAt
return time.Time{}, fmt.Errorf("%w: %s", errCouldNotGetTimeFromAnnotation, annotation)
}

var handler gatewaysecret.Handler
if flagVar.UseLegacyStrategyForIstioGatewaySecret {
handler = legacy.NewGatewaySecretHandler(clnt, parseLastModifiedFunc)
} else {
handler = cabundle.NewGatewaySecretHandler(clnt, parseLastModifiedFunc,
flagVar.IstioGatewayCertSwitchBeforeExpirationTime)
}
handler := gatewaysecret.NewGatewaySecretHandler(clnt, parseLastModifiedFunc)

var getSecretFunc GetterFunc = func(ctx context.Context, name types.NamespacedName) (*apicorev1.Secret, error) {
secret := &apicorev1.Secret{}
Expand All @@ -51,7 +63,10 @@ func SetupReconciler(mgr ctrl.Manager, flagVar *flags.FlagVar, options ctrlrunti
return secret, nil
}

return NewReconciler(getSecretFunc, handler).setupWithManager(mgr, options)
return NewReconciler(getSecretFunc, handler, queue.RequeueIntervals{
Success: flagVar.IstioGatewaySecretRequeueSuccessInterval,
Error: flagVar.IstioGatewaySecretRequeueErrInterval,
}).setupWithManager(mgr, options)
}

func (r *Reconciler) setupWithManager(mgr ctrl.Manager, opts ctrlruntime.Options) error {
Expand Down
Loading
Loading