Skip to content

Commit

Permalink
Migrate intentions from legacy intentions to config entries
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisnotashwin committed Nov 16, 2021
1 parent e5b9970 commit 68fd45c
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 49 deletions.
12 changes: 8 additions & 4 deletions acceptance/tests/connect/connect_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ func ConnectInjectConnectivityCheck(t *testing.T, ctx environment.TestContext, c
}

logger.Log(t, "creating intention")
_, err := consulClient.Connect().IntentionUpsert(&api.Intention{
SourceName: staticClientName,
DestinationName: staticServerName,
Action: api.IntentionActionAllow,
_, _, err := consulClient.ConfigEntries().Set(&api.ServiceIntentionsConfigEntry{
Name: staticServerName,
Sources: []*api.SourceIntention{
{
Name: staticClientName,
Action: api.IntentionActionAllow,
},
},
}, nil)
require.NoError(t, err)
}
Expand Down
22 changes: 13 additions & 9 deletions acceptance/tests/connect/connect_inject_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,27 @@ func TestConnectInjectNamespaces(t *testing.T) {
k8s.CheckStaticServerConnectionFailing(t, staticClientOpts, "http://localhost:1234")
}

intention := &api.Intention{
SourceName: staticClientName,
SourceNS: staticClientNamespace,
DestinationName: staticServerName,
DestinationNS: staticServerNamespace,
Action: api.IntentionActionAllow,
intention := &api.ServiceIntentionsConfigEntry{
Name: staticServerName,
Namespace: staticServerNamespace,
Sources: []*api.SourceIntention{
{
Name: staticClientName,
Namespace: staticClientNamespace,
Action: api.IntentionActionAllow,
},
},
}

// Set the destination namespace to be the same
// unless mirrorK8S is true.
if !c.mirrorK8S {
intention.SourceNS = c.destinationNamespace
intention.DestinationNS = c.destinationNamespace
intention.Namespace = c.destinationNamespace
intention.Sources[0].Namespace = c.destinationNamespace
}

logger.Log(t, "creating intention")
_, err := consulClient.Connect().IntentionUpsert(intention, nil)
_, _, err := consulClient.ConfigEntries().Set(intention, nil)
require.NoError(t, err)
}

Expand Down
32 changes: 20 additions & 12 deletions acceptance/tests/ingress-gateway/ingress_gateway_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ func TestIngressGatewaySingleNamespace(t *testing.T) {

// Now we create the allow intention.
logger.Log(t, "creating ingress-gateway => static-server intention")
_, err = consulClient.Connect().IntentionUpsert(&api.Intention{
SourceName: "ingress-gateway",
SourceNS: testNamespace,
DestinationName: "static-server",
DestinationNS: testNamespace,
Action: api.IntentionActionAllow,
_, _, err = consulClient.ConfigEntries().Set(&api.ServiceIntentionsConfigEntry{
Name: "static-server",
Namespace: testNamespace,
Sources: []*api.SourceIntention{
{
Name: "ingress-gateway",
Namespace: testNamespace,
Action: api.IntentionActionAllow,
},
},
}, nil)
require.NoError(t, err)
}
Expand Down Expand Up @@ -252,12 +256,16 @@ func TestIngressGatewayNamespaceMirroring(t *testing.T) {

// Now we create the allow intention.
logger.Log(t, "creating ingress-gateway => static-server intention")
_, err = consulClient.Connect().IntentionUpsert(&api.Intention{
SourceName: "ingress-gateway",
SourceNS: "default",
DestinationName: "static-server",
DestinationNS: testNamespace,
Action: api.IntentionActionAllow,
_, _, err = consulClient.ConfigEntries().Set(&api.ServiceIntentionsConfigEntry{
Name: "static-server",
Namespace: testNamespace,
Sources: []*api.SourceIntention{
{
Name: "ingress-gateway",
Namespace: "default",
Action: api.IntentionActionAllow,
},
},
}, nil)
require.NoError(t, err)
}
Expand Down
12 changes: 8 additions & 4 deletions acceptance/tests/ingress-gateway/ingress_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ func TestIngressGateway(t *testing.T) {

// Now we create the allow intention.
logger.Log(t, "creating ingress-gateway => static-server intention")
_, err = consulClient.Connect().IntentionUpsert(&api.Intention{
SourceName: "ingress-gateway",
DestinationName: "static-server",
Action: api.IntentionActionAllow,
_, _, err = consulClient.ConfigEntries().Set(&api.ServiceIntentionsConfigEntry{
Name: "static-server",
Sources: []*api.SourceIntention{
{
Name: "ingress-gateway",
Action: api.IntentionActionAllow,
},
},
}, nil)
require.NoError(t, err)
}
Expand Down
12 changes: 8 additions & 4 deletions acceptance/tests/mesh-gateway/mesh_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,14 @@ func TestMeshGatewaySecure(t *testing.T) {
k8s.DeployKustomize(t, primaryContext.KubectlOptions(t), cfg.NoCleanupOnFailure, cfg.DebugDirectory, "../fixtures/cases/static-client-multi-dc")

logger.Log(t, "creating intention")
_, err = primaryClient.Connect().IntentionUpsert(&api.Intention{
SourceName: staticClientName,
DestinationName: "static-server",
Action: api.IntentionActionAllow,
_, _, err = primaryClient.ConfigEntries().Set(&api.ServiceIntentionsConfigEntry{
Name: "static-server",
Sources: []*api.SourceIntention{
{
Name: staticClientName,
Action: api.IntentionActionAllow,
},
},
}, nil)
require.NoError(t, err)

Expand Down
24 changes: 14 additions & 10 deletions acceptance/tests/partitions/partitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,25 +425,29 @@ func TestPartitions(t *testing.T) {
k8s.CheckStaticServerConnectionFailing(t, serverClusterStaticClientOpts, "http://localhost:1234")
k8s.CheckStaticServerConnectionFailing(t, clientClusterStaticClientOpts, "http://localhost:1234")

intention := &api.Intention{
SourceName: staticClientName,
SourceNS: staticClientNamespace,
DestinationName: staticServerName,
DestinationNS: staticServerNamespace,
Action: api.IntentionActionAllow,
intention := &api.ServiceIntentionsConfigEntry{
Name: staticServerName,
Namespace: staticServerNamespace,
Sources: []*api.SourceIntention{
{
Name: staticClientName,
Namespace: staticClientNamespace,
Action: api.IntentionActionAllow,
},
},
}

// Set the destination namespace to be the same
// unless mirrorK8S is true.
if !c.mirrorK8S {
intention.SourceNS = c.destinationNamespace
intention.DestinationNS = c.destinationNamespace
intention.Namespace = c.destinationNamespace
intention.Sources[0].Namespace = c.destinationNamespace
}

logger.Log(t, "creating intention")
_, err := consulClient.Connect().IntentionUpsert(intention, &api.WriteOptions{Partition: defaultPartition})
_, _, err := consulClient.ConfigEntries().Set(intention, &api.WriteOptions{Partition: defaultPartition})
require.NoError(t, err)
_, err = consulClient.Connect().IntentionUpsert(intention, &api.WriteOptions{Partition: secondaryPartition})
_, _, err = consulClient.ConfigEntries().Set(intention, &api.WriteOptions{Partition: secondaryPartition})
require.NoError(t, err)
}

Expand Down
16 changes: 10 additions & 6 deletions acceptance/tests/terminating-gateway/terminating_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,16 @@ func assertNoConnectionAndAddIntention(t *testing.T, consulClient *api.Client, k
k8s.CheckStaticServerConnectionFailing(t, k8sOptions, "http://localhost:1234")

logger.Log(t, "creating static-client => static-server intention")
_, err := consulClient.Connect().IntentionUpsert(&api.Intention{
SourceName: staticClientName,
SourceNS: sourceNS,
DestinationName: staticServerName,
DestinationNS: destinationNS,
Action: api.IntentionActionAllow,
_, _, err := consulClient.ConfigEntries().Set(&api.ServiceIntentionsConfigEntry{
Name: staticServerName,
Namespace: destinationNS,
Sources: []*api.SourceIntention{
{
Name: staticClientName,
Namespace: sourceNS,
Action: api.IntentionActionAllow,
},
},
}, nil)
require.NoError(t, err)
}

0 comments on commit 68fd45c

Please sign in to comment.