Skip to content

Commit

Permalink
Backfill unit tests for peering dialler
Browse files Browse the repository at this point in the history
- Clean up some of the logic in peering dialler and acceptor
- Rename handler -> connectWebhook
  • Loading branch information
thisisnotashwin committed Jun 8, 2022
1 parent a12db71 commit de51d6c
Show file tree
Hide file tree
Showing 20 changed files with 1,204 additions and 498 deletions.
15 changes: 9 additions & 6 deletions control-plane/api/v1alpha1/peeringacceptor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ type ReconcileErrorStatus struct {
}

type SecretRefStatus struct {
// Name is the name of the secret generated.
Name string `json:"name,omitempty"`
// Key is the key of the secret generated.
Key string `json:"key,omitempty"`
// Backend is where the generated secret is stored. Currently supports the value: "kubernetes".
Backend string `json:"backend,omitempty"`
Secret `json:",inline"`
// ResourceVersion is the resource version for the secret.
ResourceVersion string `json:"latestHash,omitempty"`
}

func (pa *PeeringAcceptor) Secret() *Secret {
return pa.Spec.Peer.Secret
}

func (pa *PeeringAcceptor) SecretRef() *SecretRefStatus {
return pa.Status.SecretRef
}
11 changes: 11 additions & 0 deletions control-plane/api/v1alpha1/peeringdialer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ type PeeringDialerStatus struct {
// +optional
SecretRef *SecretRefStatus `json:"secret,omitempty"`
}

func (pd *PeeringDialer) Secret() *Secret {
if pd.Spec.Peer == nil {
return nil
}
return pd.Spec.Peer.Secret
}

func (pd *PeeringDialer) SecretRef() *SecretRefStatus {
return pd.Status.SecretRef
}
1 change: 1 addition & 0 deletions control-plane/api/v1alpha1/zz_generated.deepcopy.go

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func TestHandler_MutateWithNamespaces(t *testing.T) {

cases := []struct {
Name string
Handler Handler
Handler ConnectWebhook
Req admission.Request
ExpectedNamespaces []string
}{
{
Name: "single destination namespace 'default' from k8s 'default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -70,7 +70,7 @@ func TestHandler_MutateWithNamespaces(t *testing.T) {

{
Name: "single destination namespace 'default' from k8s 'non-default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -92,7 +92,7 @@ func TestHandler_MutateWithNamespaces(t *testing.T) {

{
Name: "single destination namespace 'dest' from k8s 'default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -114,7 +114,7 @@ func TestHandler_MutateWithNamespaces(t *testing.T) {

{
Name: "single destination namespace 'dest' from k8s 'non-default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -136,7 +136,7 @@ func TestHandler_MutateWithNamespaces(t *testing.T) {

{
Name: "mirroring from k8s 'default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -159,7 +159,7 @@ func TestHandler_MutateWithNamespaces(t *testing.T) {

{
Name: "mirroring from k8s 'dest'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -182,7 +182,7 @@ func TestHandler_MutateWithNamespaces(t *testing.T) {

{
Name: "mirroring with prefix from k8s 'default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -206,7 +206,7 @@ func TestHandler_MutateWithNamespaces(t *testing.T) {

{
Name: "mirroring with prefix from k8s 'dest'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand Down Expand Up @@ -298,13 +298,13 @@ func TestHandler_MutateWithNamespaces_ACLs(t *testing.T) {

cases := []struct {
Name string
Handler Handler
Handler ConnectWebhook
Req admission.Request
ExpectedNamespaces []string
}{
{
Name: "acls + single destination namespace 'default' from k8s 'default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -327,7 +327,7 @@ func TestHandler_MutateWithNamespaces_ACLs(t *testing.T) {

{
Name: "acls + single destination namespace 'default' from k8s 'non-default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -350,7 +350,7 @@ func TestHandler_MutateWithNamespaces_ACLs(t *testing.T) {

{
Name: "acls + single destination namespace 'dest' from k8s 'default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -373,7 +373,7 @@ func TestHandler_MutateWithNamespaces_ACLs(t *testing.T) {

{
Name: "acls + single destination namespace 'dest' from k8s 'non-default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -396,7 +396,7 @@ func TestHandler_MutateWithNamespaces_ACLs(t *testing.T) {

{
Name: "acls + mirroring from k8s 'default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -420,7 +420,7 @@ func TestHandler_MutateWithNamespaces_ACLs(t *testing.T) {

{
Name: "acls + mirroring from k8s 'dest'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -444,7 +444,7 @@ func TestHandler_MutateWithNamespaces_ACLs(t *testing.T) {

{
Name: "acls + mirroring with prefix from k8s 'default'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand All @@ -469,7 +469,7 @@ func TestHandler_MutateWithNamespaces_ACLs(t *testing.T) {

{
Name: "acls + mirroring with prefix from k8s 'dest'",
Handler: Handler{
Handler: ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand Down Expand Up @@ -640,7 +640,7 @@ func TestHandler_MutateWithNamespaces_Annotation(t *testing.T) {
})
require.NoError(err)

handler := Handler{
handler := ConnectWebhook{
Log: logrtest.TestLogger{T: t},
AllowK8sNamespacesSet: mapset.NewSet("*"),
DenyK8sNamespacesSet: mapset.NewSet(),
Expand Down
Loading

0 comments on commit de51d6c

Please sign in to comment.