Andrey Smirnov 0b347570a7
feat: use dynamic NodeAddresses/HostnameStatus in Kubernetes certs
This is a PR on a path towards removing `ApplyDynamicConfig`.

This fixes Kubernetes API server certificate generation to use dynamic
data to generate cert with proper SANs for IPs of the node.

As part of that refactored a bit apid certificate generation (without
any changes).

Added two unit-tests for apid and Kubernetes certificate generation.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2021-09-01 20:56:53 +03:00

46 lines
974 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package secrets_test
import (
"context"
"testing"
"time"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/stretchr/testify/assert"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/secrets"
)
func TestRateLimitEvents(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
inCh := make(chan controller.ReconcileEvent)
outCh := secrets.RateLimitEvents(ctx, inCh, time.Second)
inputs := 0
outputs := 0
timer := time.NewTimer(3 * time.Second)
defer timer.Stop()
LOOP:
for {
select {
case <-timer.C:
break LOOP
case <-outCh:
outputs++
case inCh <- controller.ReconcileEvent{}:
inputs++
}
}
assert.Less(t, outputs, 5)
assert.Greater(t, inputs, 15)
}