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

V2 MeshConfig Controller and TrafficPermissions CRD #2967

Merged
merged 9 commits into from
Sep 22, 2023

Conversation

thisisnotashwin
Copy link
Contributor

@thisisnotashwin thisisnotashwin commented Sep 15, 2023

Changes proposed in this PR:

  • Add Generic V2 MeshConfig Controller
  • Add CRDs for V2 TrafficPermissions (fka Intentions)

Things that need to be done in a future PR:

  • ENT Tests
  • Add the migration annotation to assume control of resources already in Consul from K8s
  • Some refactoring in the meshConfigController tests to keep them generic
  • Update Contributing guides for the V2 code

How I've tested this PR:

  • Unit/Integration tests
  • Manual testing: I spun up the latest Consul CE version with these changes and I was able to create a test TrafficPermission in Consul then delete it.

How I expect reviewers to test this PR: ☕ ☕ ☕ ☕ ☕ ☕ 👓

Checklist:

@thisisnotashwin thisisnotashwin force-pushed the ashwin/NET-5317-v2-config-controller branch 2 times, most recently from 3c604a4 to a1de453 Compare September 15, 2023 19:53
Copy link
Contributor

@DanStough DanStough left a comment

Choose a reason for hiding this comment

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

Looking awesome, @thisisnotashwin ! Left some comments as I was reading through it.

@thisisnotashwin thisisnotashwin force-pushed the ashwin/NET-5317-v2-config-controller branch 2 times, most recently from cb319c7 to a8bf220 Compare September 20, 2023 14:26
@DanStough DanStough force-pushed the ashwin/NET-5317-v2-config-controller branch from f8eb943 to bc68ecb Compare September 22, 2023 02:42
@DanStough DanStough changed the title WIP: add controller for traffic permissions V2 MeshConfig Controller and TrafficPermissions CRD Sep 22, 2023
@DanStough DanStough marked this pull request as ready for review September 22, 2023 02:43
@DanStough DanStough added pr/no-changelog PR does not need a corresponding .changelog entry pr/no-backport signals that a PR will not contain a backport label labels Sep 22, 2023
Comment on lines +41 to +62
// ConsulTenancyConfig manages settings related to Consul namespaces and partitions.
type ConsulTenancyConfig struct {
// EnableConsulPartitions indicates that a user is running Consul Enterprise.
EnableConsulPartitions bool
// ConsulPartition is the Consul Partition to which this controller belongs.
ConsulPartition string
// EnableConsulNamespaces indicates that a user is running Consul Enterprise.
EnableConsulNamespaces bool
// ConsulDestinationNamespace is the name of the Consul namespace to create
// all resources in. If EnableNSMirroring is true this is ignored.
ConsulDestinationNamespace string
// EnableNSMirroring causes Consul namespaces to be created to match the
// k8s namespace of any config entry custom resource. Resources will
// be created in the matching Consul namespace.
EnableNSMirroring bool
// NSMirroringPrefix is an optional prefix that can be added to the Consul
// namespaces created while mirroring. For example, if it is set to "k8s-",
// then the k8s `default` namespace will be mirrored in Consul's
// `k8s-default` namespace.
NSMirroringPrefix string
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactored here since this is shared by both the connect and config controllers.

cases := []struct {
name string
meshConfig common.MeshConfig
expected *pbauth.TrafficPermissions
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize these tests are suppose to be generic, but in the interest of time, I just hardcoded the TrafficPermissions structs in several places. I suspect they will get refactored shortly at the expense of some boilerplate to convert to a pbresource.Resource.

@DanStough DanStough requested a review from zalimeni September 22, 2023 03:41
Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

Had a little time this evening and started reviewing, so I thought I'd leave my half review-- I got through the _types.go and _types_test.go and all the generated files and renames and the refactor, but didn't make it to the controller itself for a thorough review in case someone is reviewing in the east coast AM!

@@ -1,21 +1,18 @@
{{- if .Values.connectInject.enabled }}
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to bring back the license headers? Probably the generation script blew them away.

Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking

group: auth
kind: TrafficPermissions
path: github.com/hashicorp/consul-k8s/control-plane/api/v2alpha1
version: v2alpha1
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: looks like Iryna updated versions in core to v2beta1 rather than alpha so we should match


TheirName string
TheirConsulNamespace string
TheirConsulPartition string
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, thanks for adding ent here, I don't think the other config entries had ent tests like this. So thorough!!

@@ -0,0 +1,11 @@
# Copyright (c) HashiCorp, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually delete the patches folder in config/crd

@@ -0,0 +1,27 @@
# Copyright (c) HashiCorp, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually delete this since it's a sample

@@ -0,0 +1,23 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

Copy link
Contributor

Choose a reason for hiding this comment

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

We usually delete since its a sample

@@ -0,0 +1,14 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

Copy link
Contributor

Choose a reason for hiding this comment

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

usually delete this since it's a sample

@@ -113,7 +114,7 @@ func TestReconcile_CreateService(t *testing.T) {
// }
// return []runtime.Object{endpoints, service}
// },
// expectedResource: &pbresource.Resource{
// expectedResource: &pbresource.MeshConfig{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not meant to be MeshConfig here since I see a Service below?

@thisisnotashwin thisisnotashwin force-pushed the ashwin/NET-5317-v2-config-controller branch from 43632ab to 72e3d0f Compare September 22, 2023 13:43
- apiGroups:
- auth.consul.hashicorp.com
apiVersions:
- v2alpha1
Copy link
Contributor

Choose a reason for hiding this comment

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

🚗 this should be v2beta1 once hashicorp/consul#18930 is merged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup!! i have incorporated those changes into this PR to ease the eventual rebase

Copy link
Contributor Author

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

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

APPROVED!!

- v1
clientConfig:
service:
name: {{ template "consul.fullname" . }}-connect-injector
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit: maybe we can call this mesh-injector? im OK moving away from the injector verbiage altogether but WDYT?

- apiGroups:
- auth.consul.hashicorp.com
apiVersions:
- v2alpha1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup!! i have incorporated those changes into this PR to ease the eventual rebase

@thisisnotashwin thisisnotashwin force-pushed the ashwin/NET-5317-v2-config-controller branch from 6e6d74f to 37309df Compare September 22, 2023 17:00
@thisisnotashwin thisisnotashwin enabled auto-merge (squash) September 22, 2023 17:02
@thisisnotashwin thisisnotashwin merged commit e57edf5 into main Sep 22, 2023
@thisisnotashwin thisisnotashwin deleted the ashwin/NET-5317-v2-config-controller branch September 22, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-backport signals that a PR will not contain a backport label pr/no-changelog PR does not need a corresponding .changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants