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

support setting resource limits on encryption provider pode #380

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1,906 changes: 1,905 additions & 1 deletion operator/charts/kit-operator/crds/control-plane-crd.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion operator/charts/kit-operator/crds/data-plane-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
name: dataplanes.kit.k8s.sh
spec:
Expand Down
2 changes: 1 addition & 1 deletion operator/hack/toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tools() {
go install github.com/mitchellh/[email protected]
go install github.com/onsi/ginkgo/[email protected]
go install sigs.k8s.io/controller-runtime/tools/[email protected]
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.11.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update this?


if ! echo "$PATH" | grep -q "${GOPATH:-undefined}/bin\|$HOME/go/bin"; then
echo "Go workspace's \"bin\" directory is not in PATH. Run 'export PATH=\"\$PATH:\${GOPATH:-\$HOME/go}/bin\"'."
Expand Down
6 changes: 5 additions & 1 deletion operator/pkg/apis/controlplane/v1alpha1/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ type Etcd struct {
// custom flags for components running on master nodes like apiserver, KCM and
// scheduler.
type MasterSpec struct {
KMSKeyID *string `json:"kmsKeyId,omitempty"`
// Provide a KMS key ID to enable the encryption provider
KMSKeyID *string `json:"kmsKeyId,omitempty"`
// The EncryptionProvider spec is used only if KMSKeyID is provided.
EncryptionProvider *Component `json:"encryptionProvider,omitempty"`

Scheduler *Component `json:"scheduler,omitempty"`
ControllerManager *Component `json:"controllerManager,omitempty"`
APIServer *Component `json:"apiServer,omitempty"`
Expand Down

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

96 changes: 54 additions & 42 deletions operator/pkg/controllers/master/awsencryptionprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/awslabs/kubernetes-iteration-toolkit/operator/pkg/utils/functional"
"github.com/awslabs/kubernetes-iteration-toolkit/operator/pkg/utils/imageprovider"
"github.com/awslabs/kubernetes-iteration-toolkit/operator/pkg/utils/object"
"github.com/awslabs/kubernetes-iteration-toolkit/operator/pkg/utils/patch"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -48,7 +49,13 @@ func (c *Controller) reconcileEncryptionProvider(ctx context.Context, controlPla
if controlPlane.Spec.Master.KMSKeyID == nil {
return nil
}
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate
encryptionProviderPodSpec := encryptionProviderPodSpecFor(controlPlane)
if controlPlane.Spec.Master.EncryptionProvider != nil {
encryptionProviderPodSpec, err = patch.PodSpec(&encryptionProviderPodSpec, controlPlane.Spec.Master.EncryptionProvider.Spec)
if err != nil {
return fmt.Errorf("patch encryption provider pod spec, %w", err)
}
}
return c.kubeClient.EnsurePatch(ctx, &appsv1.DaemonSet{},
object.WithOwner(controlPlane, &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -61,47 +68,7 @@ func (c *Controller) reconcileEncryptionProvider(ctx context.Context, controlPla
Selector: &metav1.LabelSelector{MatchLabels: providerLabels(controlPlane.ClusterName())},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: providerLabels(controlPlane.ClusterName())},
Spec: v1.PodSpec{
PriorityClassName: "system-node-critical",
Tolerations: []v1.Toleration{{Operator: v1.TolerationOpExists}},
NodeSelector: nodeSelector(controlPlane.ClusterName(), controlPlane.Spec.ColocateAPIServerWithEtcd),
Containers: []v1.Container{{
Name: "aws-encryption-provider",
Image: imageprovider.AWSEncryptionProvider(),
Command: []string{"/aws-encryption-provider"},
Args: []string{
"--key=" + aws.StringValue(controlPlane.Spec.Master.KMSKeyID),
"--listen=/var/run/kmsplugin/socket.sock",
},
Ports: []v1.ContainerPort{{ContainerPort: 8080}},
LivenessProbe: &v1.Probe{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Scheme: v1.URISchemeHTTP,
Path: "/healthz",
Port: intstr.FromInt(8080),
},
},
InitialDelaySeconds: 10,
PeriodSeconds: 5,
TimeoutSeconds: 5,
FailureThreshold: 5,
},
VolumeMounts: []v1.VolumeMount{{
Name: "var-run-kmsplugin",
MountPath: "/var/run/kmsplugin",
}},
}},
Volumes: []v1.Volume{{
Name: "var-run-kmsplugin",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/var/run/kmsplugin",
Type: &hostPathDirectoryOrCreate,
},
},
}},
},
Spec: encryptionProviderPodSpec,
},
},
}),
Expand All @@ -116,6 +83,51 @@ func providerLabels(clustername string) map[string]string {
return functional.UnionStringMaps(labelsFor(clustername), map[string]string{"component": "aws-encryption-provider"})
}

func encryptionProviderPodSpecFor(controlPlane *v1alpha1.ControlPlane) v1.PodSpec {
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate
return v1.PodSpec{
PriorityClassName: "system-node-critical",
Tolerations: []v1.Toleration{{Operator: v1.TolerationOpExists}},
NodeSelector: nodeSelector(controlPlane.ClusterName(), controlPlane.Spec.ColocateAPIServerWithEtcd),
Containers: []v1.Container{{
Name: "aws-encryption-provider",
Image: imageprovider.AWSEncryptionProvider(),
Command: []string{"/aws-encryption-provider"},
Args: []string{
"--key=" + aws.StringValue(controlPlane.Spec.Master.KMSKeyID),
"--listen=/var/run/kmsplugin/socket.sock",
},
Ports: []v1.ContainerPort{{ContainerPort: 8080}},
LivenessProbe: &v1.Probe{
ProbeHandler: v1.ProbeHandler{
HTTPGet: &v1.HTTPGetAction{
Scheme: v1.URISchemeHTTP,
Path: "/healthz",
Port: intstr.FromInt(8080),
},
},
InitialDelaySeconds: 10,
PeriodSeconds: 5,
TimeoutSeconds: 5,
FailureThreshold: 5,
},
VolumeMounts: []v1.VolumeMount{{
Name: "var-run-kmsplugin",
MountPath: "/var/run/kmsplugin",
}},
}},
Volumes: []v1.Volume{{
Name: "var-run-kmsplugin",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/var/run/kmsplugin",
Type: &hostPathDirectoryOrCreate,
},
},
}},
}
}

var (
defaultProviderConfig = `
apiVersion: v1
Expand Down