Skip to content

Commit

Permalink
Fixed bug where internet object is present with empty object even whi…
Browse files Browse the repository at this point in the history
…le it doesn't exist in the ClientIntents resource (#346)
  • Loading branch information
NetanelBollag authored Jan 24, 2024
1 parent 05e21dc commit b684779
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/intents-spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spec:
calls:
- name: server
service:
name: client
3 changes: 3 additions & 0 deletions .github/workflows/netpol-e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ jobs:
kubectl apply -f https://docs.otterize.com/code-examples/automate-network-policies/intents.yaml
echo "Validate intents spec format"
kubectl get clientintents.k8s.otterize.com -n otterize-tutorial-npol client -o yaml | awk '/spec:/,EOF' | diff -s - .github/workflows/intents-spec.yaml
# should work because there is an applied intent
echo check client log
wait_for_log $CLI1_POD 10 "Hi, I am the server, you called, may I help you?"
Expand Down
6 changes: 3 additions & 3 deletions src/operator/api/v1alpha3/clientintents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type Service struct {

type Intent struct {
//+optional
Name string `json:"name" yaml:"name"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`

//+optional
Type IntentType `json:"type,omitempty" yaml:"type,omitempty"`
Expand All @@ -168,7 +168,7 @@ type Intent struct {
AWSActions []string `json:"awsActions,omitempty" yaml:"awsActions,omitempty"`

//+optional
Internet Internet `json:"internet,omitempty" yaml:"internet,omitempty"`
Internet *Internet `json:"internet,omitempty" yaml:"internet,omitempty"`
}

type Internet struct {
Expand Down Expand Up @@ -543,7 +543,7 @@ func (in *Intent) ConvertToCloudFormat(resourceNamespace string, clientName stri
})
}

if in.Internet.Ips != nil {
if in.Internet != nil && len(in.Internet.Ips) != 0 {
intentInput.Internet = &graphqlclient.InternetConfigInput{
Ips: lo.ToSlicePtr(in.Internet.Ips),
}
Expand Down
6 changes: 5 additions & 1 deletion src/operator/api/v1alpha3/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ func (s *CloudReconcilerTestSuite) TestInternetUpload() {
Calls: []otterizev1alpha3.Intent{
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: []string{"1.1.1.1", "2.2.2.0/24"},
},
},
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: []string{"3.3.3.3"},
Ports: []int{443},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *InternetNetworkPolicyReconcilerTestSuite) TestCreateNetworkPolicySingle
Calls: []otterizev1alpha3.Intent{
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: ips,
},
},
Expand Down Expand Up @@ -182,14 +182,14 @@ func (s *InternetNetworkPolicyReconcilerTestSuite) TestCreateNetworkPolicyMultip
Calls: []otterizev1alpha3.Intent{
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: []string{endpointAIp1, endpointAip2},
Ports: []int{endpointAPort},
},
},
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: []string{endpointBIp},
Ports: []int{endpointBPort},
},
Expand Down Expand Up @@ -306,7 +306,7 @@ func (s *InternetNetworkPolicyReconcilerTestSuite) TestNetworkPolicyDeletedClean
Calls: []otterizev1alpha3.Intent{
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: ips,
}},
},
Expand Down Expand Up @@ -414,7 +414,7 @@ func (s *InternetNetworkPolicyReconcilerTestSuite) TestUpdateNetworkPolicy() {
Calls: []otterizev1alpha3.Intent{
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: ips,
},
},
Expand Down Expand Up @@ -533,7 +533,7 @@ func (s *InternetNetworkPolicyReconcilerTestSuite) TestRemoveOrphanNetworkPolicy
Calls: []otterizev1alpha3.Intent{
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: ips,
},
},
Expand Down Expand Up @@ -728,7 +728,7 @@ func (s *InternetNetworkPolicyReconcilerTestSuite) testEnforcementDisabled() {
Calls: []otterizev1alpha3.Intent{
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: []string{"1.1.1.1/32"},
},
},
Expand Down
7 changes: 7 additions & 0 deletions src/operator/webhooks/clientintents_webhook_v1alpha3.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ func (v *IntentsValidatorV1alpha3) validateSpec(intents *otterizev1alpha3.Client
}
}
if intent.Type == otterizev1alpha3.IntentTypeInternet { // every ips should be valid ip
if intent.Internet == nil {
return &field.Error{
Type: field.ErrorTypeRequired,
Field: "internet",
Detail: fmt.Sprintf("invalid intent format. type %s must contain internet object", otterizev1alpha3.IntentTypeInternet),
}
}
if intent.Internet.Ips == nil || len(intent.Internet.Ips) == 0 {
return &field.Error{
Type: field.ErrorTypeRequired,
Expand Down
2 changes: 1 addition & 1 deletion src/operator/webhooks/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (s *ValidationWebhookTestSuite) TestNameRequiredForEveryTypeExceptInternet(
_, err = s.AddIntentsV1alpha3("internet-intents", "internet-client", []otterizev1alpha3.Intent{
{
Type: otterizev1alpha3.IntentTypeInternet,
Internet: otterizev1alpha3.Internet{
Internet: &otterizev1alpha3.Internet{
Ips: []string{"1.1.1.1"},
Ports: []int{80},
},
Expand Down
6 changes: 6 additions & 0 deletions src/shared/otterizecloud/graphqlclient/schema.graphql

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

6 changes: 6 additions & 0 deletions src/shared/telemetries/telemetriesgql/schema.graphql

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

0 comments on commit b684779

Please sign in to comment.