Skip to content

Commit df34984

Browse files
authored
Merge pull request #19 from LakshK98/fix-pipeline2
feat(retinaebpfapi): pktmon enum code
2 parents e90a7a1 + fac117d commit df34984

5 files changed

Lines changed: 157 additions & 18 deletions

File tree

test/e2e/framework/azure/create-cluster-with-npm.go

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
1111
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1212
armcontainerservice "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4"
13+
armnetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v5"
1314
)
1415

1516
var (
@@ -47,6 +48,40 @@ func (c *CreateNPMCluster) Stop() error {
4748

4849
func (c *CreateNPMCluster) Run() error {
4950
// Start with default cluster template
51+
// Deploy cluster
52+
cred, err := azidentity.NewAzureCLICredential(nil)
53+
if err != nil {
54+
return fmt.Errorf("failed to obtain a credential: %w", err)
55+
}
56+
ctx, cancel := context.WithTimeout(context.Background(), clusterTimeout)
57+
defer cancel()
58+
59+
clientFactory, err := armcontainerservice.NewClientFactory(c.SubscriptionID, cred, nil)
60+
if err != nil {
61+
return fmt.Errorf("failed to create az client: %w", err)
62+
}
63+
64+
// create ip for public ip
65+
publicip := armnetwork.PublicIPAddress{
66+
Location: to.Ptr(c.Location),
67+
Name: to.Ptr(c.ClusterName + "-pip"),
68+
ID: to.Ptr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/publicIPAddresses/%s-pip", c.SubscriptionID, c.ResourceGroupName, c.ClusterName)),
69+
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
70+
IPTags: []*armnetwork.IPTag{
71+
{
72+
IPTagType: to.Ptr("FirstPartyUsage"),
73+
Tag: to.Ptr("/NonProd"),
74+
},
75+
},
76+
},
77+
}
78+
79+
err = c.createPublicIP(ctx, publicip)
80+
if err != nil {
81+
return fmt.Errorf("failed to create public ip: %w", err)
82+
}
83+
84+
// get cluster template to mutate
5085
npmCluster := GetStarterClusterTemplate(c.Location)
5186

5287
npmCluster.Properties.NetworkProfile.NetworkPolicy = to.Ptr(armcontainerservice.NetworkPolicyAzure)
@@ -99,17 +134,10 @@ func (c *CreateNPMCluster) Run() error {
99134
NodeOSUpgradeChannel: to.Ptr(armcontainerservice.NodeOSUpgradeChannelNodeImage),
100135
}
101136

102-
// Deploy cluster
103-
cred, err := azidentity.NewAzureCLICredential(nil)
104-
if err != nil {
105-
return fmt.Errorf("failed to obtain a credential: %w", err)
106-
}
107-
ctx, cancel := context.WithTimeout(context.Background(), clusterTimeout)
108-
defer cancel()
109-
110-
clientFactory, err := armcontainerservice.NewClientFactory(c.SubscriptionID, cred, nil)
111-
if err != nil {
112-
return fmt.Errorf("failed to create az client: %w", err)
137+
npmCluster.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPs.PublicIPs = []*armcontainerservice.ResourceReference{
138+
{
139+
ID: to.Ptr(*publicip.ID),
140+
},
113141
}
114142

115143
log.Printf("when the cluster is ready, use the below command to access and debug")
@@ -150,3 +178,27 @@ func (c *CreateNPMCluster) Run() error {
150178
}
151179
}
152180
}
181+
182+
func (c *CreateNPMCluster) createPublicIP(ctx context.Context, ip armnetwork.PublicIPAddress) error {
183+
cred, err := azidentity.NewAzureCLICredential(nil)
184+
if err != nil {
185+
return fmt.Errorf("failed to obtain a credential: %w", err)
186+
}
187+
clientFactory, err := armnetwork.NewClientFactory(c.SubscriptionID, cred, nil)
188+
if err != nil {
189+
return fmt.Errorf("failed to create client: %w", err)
190+
}
191+
192+
log.Printf("creating public ip \"%s\" in resource group \"%s\"...", *ip.Name, c.ResourceGroupName)
193+
194+
poller, err := clientFactory.NewPublicIPAddressesClient().BeginCreateOrUpdate(ctx, c.ResourceGroupName, *ip.Name, ip, nil)
195+
if err != nil {
196+
return fmt.Errorf("failed to finish the request for create public ip: %w", err)
197+
}
198+
199+
_, err = poller.PollUntilDone(ctx, nil)
200+
if err != nil {
201+
return fmt.Errorf("failed to pull the result for create public ip: %w", err)
202+
}
203+
return nil
204+
}

test/e2e/framework/azure/create-cluster.go

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
1010
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1111
armcontainerservice "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4"
12+
armnetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v5"
1213
)
1314

1415
const (
@@ -46,11 +47,6 @@ func (c *CreateCluster) SetNetworkPluginMode(networkPluginMode string) *CreateCl
4647
return c
4748
}
4849

49-
func (c *CreateCluster) SetPublicIP(loadBalancerOutboundIPID string) *CreateCluster {
50-
c.LoadBalancerOutboundIPID = loadBalancerOutboundIPID
51-
return c
52-
}
53-
5450
func (c *CreateCluster) Run() error {
5551
cred, err := azidentity.NewAzureCLICredential(nil)
5652
if err != nil {
@@ -83,6 +79,32 @@ func (c *CreateCluster) Run() error {
8379
template.Properties.NetworkProfile.NetworkPluginMode = to.Ptr(armcontainerservice.NetworkPluginMode(c.networkPluginMode))
8480
}
8581

82+
// Create LB public ip with tag
83+
publicip := armnetwork.PublicIPAddress{
84+
Location: to.Ptr(c.Location),
85+
Name: to.Ptr(c.ClusterName + "-pip"),
86+
ID: to.Ptr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/publicIPAddresses/%s-pip", c.SubscriptionID, c.ResourceGroupName, c.ClusterName)),
87+
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
88+
IPTags: []*armnetwork.IPTag{
89+
{
90+
IPTagType: to.Ptr("FirstPartyUsage"),
91+
Tag: to.Ptr("/NonProd"),
92+
},
93+
},
94+
},
95+
}
96+
97+
err = c.createPublicIP(ctx, publicip)
98+
if err != nil {
99+
return fmt.Errorf("failed to create public ip: %w", err)
100+
}
101+
102+
template.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPs.PublicIPs = []*armcontainerservice.ResourceReference{
103+
{
104+
ID: to.Ptr(*publicip.ID),
105+
},
106+
}
107+
86108
log.Printf("creating cluster %s in location %s...", c.ClusterName, c.Location)
87109
poller, err := clientFactory.NewManagedClustersClient().BeginCreateOrUpdate(ctx, c.ResourceGroupName, c.ClusterName, template, nil)
88110
if err != nil {
@@ -161,3 +183,27 @@ func (c *CreateCluster) Prevalidate() error {
161183
func (c *CreateCluster) Stop() error {
162184
return nil
163185
}
186+
187+
func (c *CreateCluster) createPublicIP(ctx context.Context, ip armnetwork.PublicIPAddress) error {
188+
cred, err := azidentity.NewAzureCLICredential(nil)
189+
if err != nil {
190+
return fmt.Errorf("failed to obtain a credential: %w", err)
191+
}
192+
clientFactory, err := armnetwork.NewClientFactory(c.SubscriptionID, cred, nil)
193+
if err != nil {
194+
return fmt.Errorf("failed to create client: %w", err)
195+
}
196+
197+
log.Printf("creating public ip \"%s\" in resource group \"%s\"...", *ip.Name, c.ResourceGroupName)
198+
199+
poller, err := clientFactory.NewPublicIPAddressesClient().BeginCreateOrUpdate(ctx, c.ResourceGroupName, *ip.Name, ip, nil)
200+
if err != nil {
201+
return fmt.Errorf("failed to finish the request for create public ip: %w", err)
202+
}
203+
204+
_, err = poller.PollUntilDone(ctx, nil)
205+
if err != nil {
206+
return fmt.Errorf("failed to pull the result for create public ip: %w", err)
207+
}
208+
return nil
209+
}

test/e2e/framework/azure/create-publicip.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package azure
22

3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
8+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
9+
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
10+
armnetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v5"
11+
)
12+
313
type CreatePublicIp struct {
414
SubscriptionID string
515
ResourceGroupName string
@@ -10,6 +20,37 @@ type CreatePublicIp struct {
1020
}
1121

1222
func (c *CreatePublicIp) Run() error {
23+
cred, err := azidentity.NewAzureCLICredential(nil)
24+
if err != nil {
25+
return fmt.Errorf("failed to obtain a credential: %w", err)
26+
}
27+
ctx := context.Background()
28+
clientFactory, err := armnetwork.NewClientFactory(c.SubscriptionID, cred, nil)
29+
if err != nil {
30+
return fmt.Errorf("failed to create client: %w", err)
31+
}
32+
33+
log.Printf("creating public ip \"%s\" in resource group \"%s\"...", c.PublicIpName, c.ResourceGroupName)
34+
35+
poller, err := clientFactory.NewPublicIPAddressesClient().BeginCreateOrUpdate(ctx, c.ResourceGroupName, c.PublicIpName, armnetwork.PublicIPAddress{
36+
Location: to.Ptr(c.Location),
37+
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
38+
IPTags: []*armnetwork.IPTag{
39+
{
40+
IPTagType: to.Ptr(c.IPTagType),
41+
Tag: to.Ptr(c.Tag),
42+
},
43+
},
44+
},
45+
}, nil)
46+
if err != nil {
47+
return fmt.Errorf("failed to finish the request for create public ip: %w", err)
48+
}
49+
50+
_, err = poller.PollUntilDone(ctx, nil)
51+
if err != nil {
52+
return fmt.Errorf("failed to pull the result for create public ip: %w", err)
53+
}
1354
return nil
1455
}
1556

test/e2e/tools/event-writer/bpf_event_writer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void create_drop_event(struct drop_notify* drp_elm)
132132
void create_pktmon_drop_event(struct pktmon_notify* drp_elm)
133133
{
134134
memset(drp_elm, 0, sizeof(struct pktmon_notify));
135-
drp_elm->type = CILIUM_NOTIFY_DROP;
135+
drp_elm->type = PKTMON_NOTIFY_DROP;
136136
drp_elm->subtype = 7;
137137
drp_elm->source = 10; // random source
138138
drp_elm->hash = 0;

test/e2e/tools/event-writer/event_writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ enum {
3535
CILIUM_NOTIFY_POLICY_VERDICT,
3636
CILIUM_NOTIFY_CAPTURE,
3737
CILIUM_NOTIFY_TRACE_SOCK,
38-
PKTMON_NOTIFY_DROP,
38+
PKTMON_NOTIFY_DROP = 100,
3939
};
4040

4141
enum {

0 commit comments

Comments
 (0)