-
Notifications
You must be signed in to change notification settings - Fork 16
Accept PodSecurityPolicy name, bind to managed ServiceAccount if provided #433
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal review
@@ -73,6 +73,10 @@ spec: | |||
namespace: | |||
description: The Consul namespace to use for authentication. | |||
type: string | |||
podSecurityPolicy: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of having this named explicitly after podSecurityPolicy
since it's already going away w/ K8s 1.25; however, the replacement for it is different enough that I don't think it makes sense to try and munge the concepts together into one field. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like that it's so explicit. That will make it easier when we remove PSPs in a few years. What is our support policy for K8s versions?
//+kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=roles;rolebindings,verbs=list;get;create;watch | ||
//+kubebuilder:rbac:groups=policy,resources=podsecuritypolicies,verbs=use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RBAC generated from these annotations is only used for our own testing inside this repo. These changes reflect the changes that have already been made to the Consul Helm chart in hashicorp/consul-k8s#1672
role := config.RoleFor(gateway) | ||
if role == nil { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the pattern already established by the ServiceAccount
code immediately above: return nil
if we shouldn't be creating a Role
and move along.
APIGroup: "rbac.authorization.k8s.io", | ||
Kind: "Role", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked for some constants for these but had no luck finding any in the K8s SDK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I like that you included some refactoring work as well to keep things tidy
@@ -73,6 +73,10 @@ spec: | |||
namespace: | |||
description: The Consul namespace to use for authentication. | |||
type: string | |||
podSecurityPolicy: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like that it's so explicit. That will make it easier when we remove PSPs in a few years. What is our support policy for K8s versions?
@@ -437,6 +438,14 @@ func (g *gatewayClient) DeleteService(ctx context.Context, service *core.Service | |||
return nil | |||
} | |||
|
|||
func (g *gatewayClient) EnsureExists(ctx context.Context, obj client.Object, mutators ...func() error) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really clean implementation!
Changes proposed in this PR:
When creating a
Deployment
for a givenGateway
, we create a "managed"ServiceAccount
if theGatewayClassConfig
indicates that we should.With the changes in this PR, we will also create a
Role
andRoleBinding
attaching the namedpodSecurityPolicy
from theGatewayClassConfig
if one has been provided.How I've tested this PR:
Create a K8s cluster that requires
PodSecurityPolicies
. In GKE, this is:Install the Consul Helm chart from hashicorp/consul-k8s#1672 and exercise Consul API Gateway functionality.
How I expect reviewers to test this PR:
See above
Checklist: