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

[Release-1.30] Testing And Secrets-Encryption Backports for 2024-09 #10801

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ steps:
UPGRADE_CHANNEL="latest"
else
UPGRADE_CHANNEL=$(echo $DRONE_BRANCH | sed 's/release-/v/')
# Check if the UPGRADE_CHANNEL exists, in the case of new minor releases it won't
if ! curl --head --silent --fail https://update.k3s.io/v1-release/channels/$UPGRADE_CHANNEL; then
UPGRADE_CHANNEL="latest"
fi
fi
E2E_RELEASE_CHANNEL=$UPGRADE_CHANNEL go test -v -timeout=45m ./upgradecluster_test.go -ci -local
cp ./coverage.out /tmp/artifacts/upgrade-coverage.out
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
with:
path: |
~/.vagrant.d/boxes
key: vagrant-box-ubuntu-2204
key: vagrant-box-ubuntu-2404
- name: "Vagrant Plugin(s)"
run: vagrant plugin install vagrant-k3s vagrant-reload vagrant-scp

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
vm: [centos-7, rocky-8, rocky-9, fedora, opensuse-leap, ubuntu-2204]
vm: [centos-9, rocky-8, rocky-9, fedora, opensuse-leap, ubuntu-2404]
max-parallel: 3
defaults:
run:
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
vagrant ssh -c "sudo mv /tmp/k3s /usr/local/bin/k3s"
vagrant provision --provision-with=k3s-upload
- name: Add binary to PATH
if: matrix.vm == 'centos-7' || matrix.vm == 'rocky-8' || matrix.vm == 'rocky-9' || matrix.vm == 'opensuse-leap'
if: matrix.vm == 'centos-9' || matrix.vm == 'rocky-8' || matrix.vm == 'rocky-9' || matrix.vm == 'opensuse-leap'
run: vagrant provision --provision-with=add-bin-path
- name: "⏩ Install K3s"
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
channel: [stable, latest]
vm: [rocky-8, fedora, opensuse-leap, ubuntu-2204]
vm: [rocky-9, fedora, opensuse-leap, ubuntu-2404]
max-parallel: 4
defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FROM vagrantlibvirt/vagrant-libvirt:0.12.1 AS test-e2e
RUN apt-get update && apt-get install -y docker.io
ENV VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1
RUN vagrant plugin install vagrant-k3s vagrant-reload vagrant-scp
RUN vagrant box add generic/ubuntu2204 --provider libvirt --force
RUN vagrant box add bento/ubuntu-24.04 --provider libvirt --force
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"; \
chmod +x ./kubectl; \
mv ./kubectl /usr/local/bin/kubectl
Expand Down
2 changes: 0 additions & 2 deletions pkg/daemons/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ type Control struct {
ClusterInit bool
ClusterReset bool
ClusterResetRestorePath string
EncryptForce bool
EncryptSkip bool
MinTLSVersion string
CipherSuites []string
TLSMinVersion uint16 `json:"-"`
Expand Down
13 changes: 0 additions & 13 deletions pkg/daemons/control/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/daemons/control/deps"
"github.com/k3s-io/k3s/pkg/daemons/executor"
"github.com/k3s-io/k3s/pkg/secretsencrypt"
"github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors"
Expand Down Expand Up @@ -61,18 +60,6 @@ func Server(ctx context.Context, cfg *config.Control) error {
if err := apiServer(ctx, cfg); err != nil {
return err
}
if cfg.EncryptSecrets {
controllerName := "reencrypt-secrets"
cfg.Runtime.ClusterControllerStarts[controllerName] = func(ctx context.Context) {
// cfg.Runtime.Core is populated before this callback is triggered
if err := secretsencrypt.Register(ctx,
controllerName,
cfg,
cfg.Runtime.Core.Core().V1().Node()); err != nil {
logrus.Errorf("Failed to register %s controller: %v", controllerName, err)
}
}
}
}

// Wait for an apiserver to become available before starting additional controllers,
Expand Down
46 changes: 32 additions & 14 deletions pkg/secretsencrypt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ import (
)

const (
EncryptionStart string = "start"
EncryptionPrepare string = "prepare"
EncryptionRotate string = "rotate"
EncryptionRotateKeys string = "rotate_keys"
EncryptionReencryptRequest string = "reencrypt_request"
EncryptionReencryptActive string = "reencrypt_active"
EncryptionReencryptFinished string = "reencrypt_finished"
EncryptionStart string = "start"
EncryptionPrepare string = "prepare"
EncryptionRotate string = "rotate"
EncryptionRotateKeys string = "rotate_keys"
EncryptionReencryptRequest string = "reencrypt_request"
EncryptionReencryptActive string = "reencrypt_active"
EncryptionReencryptFinished string = "reencrypt_finished"
SecretListPageSize int64 = 20
SecretQPS float32 = 200
SecretBurst int = 200
SecretsUpdateErrorEvent string = "SecretsUpdateError"
SecretsProgressEvent string = "SecretsProgress"
SecretsUpdateCompleteEvent string = "SecretsUpdateComplete"
)

var EncryptionHashAnnotation = version.Program + ".io/encryption-config-hash"
Expand Down Expand Up @@ -178,7 +184,9 @@ func BootstrapEncryptionHashAnnotation(node *corev1.Node, runtime *config.Contro
return nil
}

func WriteEncryptionHashAnnotation(runtime *config.ControlRuntime, node *corev1.Node, stage string) error {
// WriteEncryptionHashAnnotation writes the encryption hash to the node annotation and optionally to a file.
// The file is used to track the last stage of the reencryption process.
func WriteEncryptionHashAnnotation(runtime *config.ControlRuntime, node *corev1.Node, skipFile bool, stage string) error {
encryptionConfigHash, err := GenEncryptionConfigHash(runtime)
if err != nil {
return err
Expand All @@ -192,6 +200,9 @@ func WriteEncryptionHashAnnotation(runtime *config.ControlRuntime, node *corev1.
return err
}
logrus.Debugf("encryption hash annotation set successfully on node: %s\n", node.ObjectMeta.Name)
if skipFile {
return nil
}
return os.WriteFile(runtime.EncryptionHash, []byte(ann), 0600)
}

Expand Down Expand Up @@ -253,10 +264,11 @@ func GetEncryptionConfigMetrics(runtime *config.ControlRuntime, initialMetrics b
return true, err
}
tsMetric := mf["apiserver_encryption_config_controller_automatic_reload_last_timestamp_seconds"]
successMetric := mf["apiserver_encryption_config_controller_automatic_reload_success_total"]
// Potentially multiple metrics with different success/failure labels
totalMetrics := mf["apiserver_encryption_config_controller_automatic_reloads_total"]

// First time, no metrics exist, so return zeros
if tsMetric == nil && successMetric == nil && initialMetrics {
if tsMetric == nil && totalMetrics == nil && initialMetrics {
return true, nil
}

Expand All @@ -265,8 +277,8 @@ func GetEncryptionConfigMetrics(runtime *config.ControlRuntime, initialMetrics b
return false, nil
}

if successMetric == nil {
lastFailure = "encryption config success metric not found"
if totalMetrics == nil {
lastFailure = "encryption config total metric not found"
return false, nil
}

Expand All @@ -275,8 +287,14 @@ func GetEncryptionConfigMetrics(runtime *config.ControlRuntime, initialMetrics b
return true, fmt.Errorf("encryption reload time is incorrectly ahead of current time")
}

reloadSuccessCounter = int64(successMetric.GetMetric()[0].GetCounter().GetValue())

for _, totalMetric := range totalMetrics.GetMetric() {
logrus.Debugf("totalMetric: %+v", totalMetric)
for _, label := range totalMetric.GetLabel() {
if label.GetName() == "status" && label.GetValue() == "success" {
reloadSuccessCounter = int64(totalMetric.GetCounter().GetValue())
}
}
}
return true, nil
})

Expand Down
Loading
Loading