Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix subnetwork SecondaryIpRanges update issue #517

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/clients/subnetwork/subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func IsUpToDate(name string, in *v1beta1.SubnetworkParameters, observed *compute
if !ok {
return true, false, errors.New(errCheckUpToDate)
}
// empty the SecondaryIpRanges to ensure that SecondaryRanges will be deleted
// when the user removes them from the CR.
desired.SecondaryIpRanges = make([]*compute.SubnetworkSecondaryRange, 0)
GenerateSubnetwork(name, *in, desired)
if !cmp.Equal(desired.PrivateIpGoogleAccess, observed.PrivateIpGoogleAccess) {
return false, true, nil
Expand Down
15 changes: 15 additions & 0 deletions pkg/clients/subnetwork/subnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func params(m ...func(*v1beta1.SubnetworkParameters)) *v1beta1.SubnetworkParamet
return o
}

func removeSecondaryRanges(s *v1beta1.SubnetworkParameters) {
s.SecondaryIPRanges = nil
}

func subnetwork(m ...func(*compute.Subnetwork)) *compute.Subnetwork {
o := &compute.Subnetwork{
Description: testDescription,
Expand Down Expand Up @@ -292,6 +296,17 @@ func TestIsUpToDate(t *testing.T) {
},
want: want{upToDate: false, privAcc: true},
},
"NotUpToDateSecondaryRanges": {
args: args{
name: testName,
in: params(removeSecondaryRanges),
current: subnetwork(),
},
want: want{
upToDate: false,
privAcc: false,
},
},
}

for name, tc := range cases {
Expand Down