Skip to content

Commit

Permalink
Merge pull request #8 from morpheu/tsuruapp_additionalips
Browse files Browse the repository at this point in the history
add additionalips for tsuruapp
  • Loading branch information
morpheu authored Sep 4, 2023
2 parents 532961c + 1ba8f30 commit a025ef4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/v1alpha1/tsuru_app_address_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (

// TsuruAppAddressSpec defines the desired state of TsuruAppAddress
type TsuruAppAddressSpec struct {
Name string `json:"name,omitempty"`
Name string `json:"name,omitempty"`
AdditionalIPs []string `json:"additionalIPs,omitempty"`
}

// ResourceAddressStatus defines the observed state of TsuruAppAddress and RpaasInstanceAddress
Expand Down
15 changes: 15 additions & 0 deletions controllers/acl_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,21 @@ func (r *ACLReconciler) egressRulesForTsuruApp(ctx context.Context, tsuruApp str
allErrors.Add(err)
}

additionalIPs := []netv1.NetworkPolicyPeer{}
for _, ip := range existingTsuruAppAddress.Spec.AdditionalIPs {
cidr := ipToCIDR(ip)
if cidr == "" {
continue
}

additionalIPs = append(additionalIPs, netv1.NetworkPolicyPeer{IPBlock: &netv1.IPBlock{
CIDR: cidr,
}})
}
if len(additionalIPs) > 0 {
egress = append(egress, []netv1.NetworkPolicyEgressRule{{To: additionalIPs}}...)
}

return egress, allErrors.ToError()
}

Expand Down
20 changes: 19 additions & 1 deletion controllers/acl_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ func (suite *ControllerSuite) TestACLReconcilerDestinationAppReconcile() {
},
Spec: v1alpha1.TsuruAppAddressSpec{
Name: "my-other-app",
AdditionalIPs: []string{
"3.3.3.3",
"4.4.4.4",
},
},
Status: v1alpha1.ResourceAddressStatus{
Ready: true,
Expand Down Expand Up @@ -384,12 +388,13 @@ func (suite *ControllerSuite) TestACLReconcilerDestinationAppReconcile() {
suite.Assert().Equal(map[string]string{
"tsuru.io/app-name": "myapp",
}, existingNP.Spec.PodSelector.MatchLabels)
suite.Assert().Len(existingNP.Spec.Egress, 4)
suite.Assert().Len(existingNP.Spec.Egress, 5)

suite.Assert().Len(existingNP.Spec.Egress[0].To, 1)
suite.Assert().Len(existingNP.Spec.Egress[1].To, 1)
suite.Assert().Len(existingNP.Spec.Egress[2].To, 1)
suite.Assert().Len(existingNP.Spec.Egress[3].To, 1)
suite.Assert().Len(existingNP.Spec.Egress[4].To, 2)

suite.Assert().Equal(netv1.NetworkPolicyPeer{
PodSelector: &metav1.LabelSelector{
Expand Down Expand Up @@ -423,6 +428,19 @@ func (suite *ControllerSuite) TestACLReconcilerDestinationAppReconcile() {
CIDR: "2.2.2.2/32",
},
}, existingNP.Spec.Egress[3].To[0])

suite.Assert().Equal([]netv1.NetworkPolicyPeer{
{
IPBlock: &netv1.IPBlock{
CIDR: "3.3.3.3/32",
},
},
{
IPBlock: &netv1.IPBlock{
CIDR: "4.4.4.4/32",
},
},
}, existingNP.Spec.Egress[4].To)
}

func (suite *ControllerSuite) TestACLReconcilerDestinationExternalDNSReconcile() {
Expand Down

0 comments on commit a025ef4

Please sign in to comment.