Commit Graph

103432 Commits

Author SHA1 Message Date
Tim Hockin
f94782b4f5 Svc REST: rename allocServiceClusterIPsNew 2021-09-11 11:30:01 -07:00
Tim Hockin
8f5189a49f Svc REST: Move tests and scaffolding around
No code edits.  Just a little whitespace, adding comments, and
re-ordering functions.
2021-09-11 11:30:01 -07:00
Tim Hockin
017a430dcd Svc REST: Move patchAllocatedValues to storage pkg
All the meaningful callers of it are in that pkg anyway.  Removes 1
FIXME.
2021-09-11 11:30:01 -07:00
Tim Hockin
4ff4160e34 Svc REST: Move normalizeClusterIPs to storage pkg
All the meaningful callers of it are in that pkg anyway.  Removes some
FIXMEs.
2021-09-11 11:30:01 -07:00
Tim Hockin
4718a0f214 DeepCopy() input objects in Service REST test
Since the PR to do this deeper in the stack was declined, we'll do it
ourselves.  This ensures that we don't accidentally mutate the input and
then compare that mutated form to the result (which caused previous test
failures).
2021-09-11 11:30:01 -07:00
Tim Hockin
4ac7c73b2e Svc REST: Remove old rest_test
All the tests have been ported to storage_test.go
2021-09-11 11:30:01 -07:00
Tim Hockin
b6da6c9c0f Svc REST: Add InternalTrafficPolicy tests
Remove older form.
2021-09-11 11:30:01 -07:00
Tim Hockin
c71467def0 Svc REST: Remove overlapping rest_tests
Most are moved to storage_test
2021-09-11 11:30:01 -07:00
Tim Hockin
12ac38f661 Svc REST: Beef up ports test, remove old form 2021-09-11 11:30:01 -07:00
Tim Hockin
652dc8787c Svc REST: Use "prove" helpers in other tests 2021-09-11 11:30:01 -07:00
Tim Hockin
245a654dec Svc REST: Rename service NewGenericREST to NewREST
Just like all the other registries.
2021-09-11 11:30:01 -07:00
Tim Hockin
03e7690cdb Svc REST: Remove old, now unused stubs 2021-09-11 11:30:01 -07:00
Tim Hockin
8e68b587e8 Svc REST: De-layering done! Convert to 1 layer
This is the culmination of all the previous commits which made this last
move less dramatic.  More tests and cleanup commits will follow.

Background, for future archaeologists:

Service has (had) an "outer" and "inner" REST handler.  This is because of how we do IP and port allocations synchronously, but since we don't have API transactions, we need to roll those back in case of a failure.  Both layers use the same `Strategy`, but the outer calls into the inner, which causes a lot of complexity in the code (including an open-coded partial reimplementation of a date-unknown snapshot of the generic REST code) and results in `Prepare` and `Validate` hooks being called twice.

The "normal" REST flow seems to be:

```
mutating webhooks
generic REST store Create {
    cleanup = BeginCreate
    BeforeCreate {
        strategy.PrepareForCreate {
            dropDisabledFields
        }
        strategy.Validate
        strategy.Canonicalize
    }
    createValidation (validating webhooks)
    storage Create
    cleanup
    AfterCreate
    Decorator
}
```

Service (before this series of commits) does:

```
mutating webhooks
svc custom Create {
    BeforeCreate {
        strategy.PrepareForCreate {
            dropDisabledFields
        }
        strategy.Validate
        strategy.Canonicalize
    }
    Allocations
    inner (generic) Create {
        cleanup = BeginCreate
        BeforeCreate {
            strategy.PrepareForCreate {
                dropDisabledFields
            }
            strategy.Validate
            strategy.Canonicalize
        }
        createValidation (validating webhooks)
        storage Create
        cleanup
        AfterCreate
        Decorator
    }
}
```

After this:

```
mutating webhooks
generic REST store Create {
    cleanup = BeginCreate
        Allocations
    BeforeCreate {
        strategy.PrepareForCreate {
            dropDisabledFields
        }
        strategy.Validate
        strategy.Canonicalize
    }
    createValidation (validating webhooks)
    storage Create
    cleanup
    AfterCreate
        Rollback allocations on error
    Decorator
}
```
2021-09-11 11:30:01 -07:00
Tim Hockin
cf4804643a Svc REST: Remove obviously unused args
This is part of the de-layering conclusion and cleanup.

Bridge the old tests into the new REST.  This will all be removed soon.
2021-09-11 11:30:01 -07:00
Tim Hockin
d30ae6a5ab Svc REST: Make ipFamilyPolicy authoritative
Previously we would try to infer the `ipFamilyPolicy` from `clusterIPs`
and/or `ipFamilies`.  That is too tricky.  Now you MUST specify
`ipFamilyPolicy` as one of the dual-stack options in order to get a
dual-stack service.
2021-09-11 11:30:01 -07:00
Tim Hockin
ca8cfdcae9 Svc REST: Fix single<->dual-stack updates
This removes the old rest_tests and adds significantly more coverage.
Maybe too much.  The v4,v6 and v6,v4 tables are identical but for the
order of families.

This exposed that `trimFieldsForDualStackDowngrade` is called too late
to do anything (since we don't run strategy twice any more).  I moved
similar logic to `PatchAllocatedValues` but I hit on some unclarity.

Specifically, consider a PATCH operation.

Assume I have a valid dual-stack service (with 2 IPs, 2 families, and
policy either require or prefer). What fields can I patch, on their own,
to trigger a downgrade to single-stack?

I think patching policy to "single" is pretty clear intent.

But what if I leave policy and only patch `ipFamilies` down to a single
value (without violating the "can't change first family" rule)?

Or what if I patch `clusterIPs` down to a single IP value?

After much discussion, we decided to make a small API change (OK since
we are beta).  When you want a dual-stack Service you MUST specify the
`ipFamilyPolicy`.  Now we can infer less and avoid ambiguity.
2021-09-11 11:30:01 -07:00
Tim Hockin
650f8cfd35 Svc REST: Validate input before IP allocation
This commit started as removing FIXME comments, but in doing so I
realized that the IP allocation process was using unvalidated user
input.  Before de-layering, validation was called twice - once before
init and once after, which the init code depended on.

Fortunately (or not?) we had duplicative checks that caught errors but
with less friendly messages.

This commit calls validation before initializing the rest of the
IP-related fields.

This also re-organizes that code a bit, cleans up error messages and
comments, and adds a test SPECIFICALLY for the errors in those cases.
2021-09-11 11:30:01 -07:00
Tim Hockin
7602260d0a Svc REST: Fix comments to make next commits easier 2021-09-11 11:30:01 -07:00
Tim Hockin
d1b83bad67 Svc REST: Move ResourceLocation() to 'inner' layer
Part of the de-layering effort.

Also move the test.
2021-09-11 11:30:01 -07:00
Tim Hockin
7887c4c8fc Svc REST: allow tests to set cluster IP families 2021-09-11 11:30:01 -07:00
Tim Hockin
aea90a2324 Svc REST: add a beforeUpdate hook in feature tests 2021-09-11 11:30:01 -07:00
Tim Hockin
ced629e657 Svc REST: Add proof funcs in feature test logic
Allows for more control of tests to assert specific things.
2021-09-11 11:30:01 -07:00
Tim Hockin
8bcba526b6 Svc REST: Better errors on stack-downgrades
Converting dual-stack to single-stack needs good errors.
2021-09-11 11:30:01 -07:00
Tim Hockin
7cf75dbdd8 Svc REST: Beef up NodePort tests
Remove old test from rest_test.go.
2021-09-11 11:30:01 -07:00
Tim Hockin
7b1e43665d Svc REST: Change ETP create test to a feature test
All the same test cases and more.
2021-09-11 11:30:01 -07:00
Tim Hockin
f4521aa75a Fix validation on ETP: "" is not valid
This was causing tests to pass which ought not be passing.  This is not
an API change because we default the value of it when needed.  So we
would never see this in the wild, but it makes the tests sloppy.
2021-09-11 11:30:01 -07:00
Tim Hockin
5363f1646f Svc REST: Add new model of feature tests
This scaffolding allows us to assert more on each test case, and more
consistently.

Set input fields from output fields IFF they are expected AND not set on
input.  This allows us to verify the "after" state (expected) whether
the test case specified the value or not, and still pass the generic
cmp.Equal.

Use this in a few tests to prove its worth, more to do.

Some of the existing tests that are focused on create and delete can
probably be replaced by these.

This could be used in other test cases that are open-coding a lot of the
same stuff.  Later commits.
2021-09-11 11:30:00 -07:00
Tim Hockin
446a2c730d Svc REST: Add a test for PatchAllocatedValues 2021-09-11 11:30:00 -07:00
Tim Hockin
30bd8198e3 Svc REST: Set Cluster IPs during dry-run Update()
Dry-run should return valid results.

Also add a test.
2021-09-11 11:30:00 -07:00
Tim Hockin
ccf3376570 Svc REST: De-layer Update
This is the last layered method.  All allocator logic is moved to the
beginUpdate() path.  Removing the now-useless layer will happen in a
subsequent commit.
2021-09-11 11:30:00 -07:00
Tim Hockin
89a9ca52bc Svc REST: Add a delete-with-finalizer test
This is a long-standing bug that gets fixed "for free" in the
de-layering.
2021-09-11 11:30:00 -07:00
Tim Hockin
cb4d8700d3 Svc REST: Clean up redundant delete tests 2021-09-11 11:30:00 -07:00
Tim Hockin
61a5e7498d Svc REST: De-layer Delete
Gut the "outer" Delete() and move it to the inner AfterDelete().
2021-09-11 11:30:00 -07:00
Tim Hockin
42b53d850d Svc REST: Move test to reduce diff in next commits
No changes - just move.
2021-09-11 11:01:44 -07:00
Tim Hockin
6d640aa244 Svc REST: Remove redundant Get test 2021-09-11 11:01:32 -07:00
Tim Hockin
15c513cc36 Svc REST: IP and port reallocation
Make sure the logic that was covered in rest_test is covered in
storage_test.
2021-09-11 11:01:23 -07:00
Tim Hockin
a957f63ec5 Svc REST: HealthCheckNodePort tests
This commit ports the ExternalTrafficPolicy and HealthCheckNodePort
tests from rest_test to storage_test.  It's not a direct port, though.
I have added more cases (much more exhaustive) and more assertions.
2021-09-11 11:01:07 -07:00
Tim Hockin
2212924a96 Svc REST: Better NodePort tests
This commit ports the NodePort test from rest_test to storage_test.
It's not a direct port, though.  I have added many more cases (much more
exhaustive) and more assertions.

This includes cases for gate MixedProtocolLBService.
2021-09-11 11:00:44 -07:00
Tim Hockin
46d7289655 Svc REST: Remove redundant Create tests
These cases are all covered in storage_test.
2021-09-11 11:00:29 -07:00
Tim Hockin
0dc509a0c8 Svc REST: Test that Headless doesn't set IPs 2021-09-11 11:00:11 -07:00
Tim Hockin
9ca582f3b7 Svc REST: Test that ExternalName doesn't set IPs 2021-09-11 10:59:30 -07:00
Tim Hockin
ca4a95ee49 Svc REST: Dedup tests for defaulting 2021-09-11 10:59:02 -07:00
Tim Hockin
b880d3a149 Svc REST: better test checks in new tests
"Has()" was strengthened in the older rest_test, now in the newer.
2021-09-11 10:58:32 -07:00
Tim Hockin
e338c9db4b Svc REST: Set Cluster IPs during dry-run Create
Dry-run should behave like a real API call and return valid results.
2021-09-11 10:57:01 -07:00
Tim Hockin
52856f3fbe Add dry-run support to the IP allocator subsystem 2021-09-11 10:56:39 -07:00
Tim Hockin
237434bd42 Svc REST: Overhaul Create test wrt dual-stack
This includes a few cases.

1) TestCreateIgnoresIPFamilyForExternalName: Prove that ExternalName is
ignored for dual-stack.  A small set of test cases were chosen to
demonstrate.

2) TestCreateIgnoresIPFamilyWithoutDualStack: Prove that when the
dual-stack gate is off, all services are ignored for dual-stack.  A
small set of test cases were chosen to demonstrate

3) TestCreateInitIPFields: Run over a huge array of test cases for
dual-stack.  This was generated by this program:
https://gist.github.com/thockin/cccc9c9a580b4830ee0946ddd43eeafe and
then updated by hand.
2021-09-11 10:56:03 -07:00
Tim Hockin
e4c6d0837e Svc REST: Rename some tests for clarity 2021-09-11 10:55:51 -07:00
Tim Hockin
bdbf2c6ef4 Svc REST: Allow multi-IP-family in tests 2021-09-11 10:54:24 -07:00
Tim Hockin
6cc9ef3874 Svc REST: Rename a long, hard function name 2021-09-11 10:54:03 -07:00
Tim Hockin
634055bded Svc REST: De-layer Create
Gut the "outer" Create() and move it to the inner BeginCreate().  This
uses a "transaction" type to make cleanup functions easy to read.

Background:

Service has an "outer" and "inner" REST handler.  This is because of how we do IP and port allocations synchronously, but since we don't have API transactions, we need to roll those back in case of a failure.  Both layers use the same `Strategy`, but the outer calls into the inner, which causes a lot of complexity in the code (including an open-coded partial reimplementation of a date-unknown snapshot of the generic REST code) and results in `Prepare` and `Validate` hooks being called twice.

The "normal" REST flow seems to be:

```
mutating webhooks
generic REST store Create {
    cleanup = BeginCreate
    BeforeCreate {
        strategy.PrepareForCreate {
            dropDisabledFields
        }
        strategy.Validate
        strategy.Canonicalize
    }
    createValidation (validating webhooks)
    storage Create
    cleanup
    AfterCreate
    Decorator
}
```

Service (before this commit) does:

```
mutating webhooks
svc custom Create {
    BeforeCreate {
        strategy.PrepareForCreate {
            dropDisabledFields
        }
        strategy.Validate
        strategy.Canonicalize
    }
    Allocations
    inner (generic) Create {
        cleanup = BeginCreate
        BeforeCreate {
            strategy.PrepareForCreate {
                dropDisabledFields
            }
            strategy.Validate
            strategy.Canonicalize
        }
        createValidation (validating webhooks)
        storage Create
        cleanup
        AfterCreate
        Decorator
    }
}
```

After this commit:

```
mutating webhooks
generic REST store Create {
    cleanup = BeginCreate
        Allocations
    BeforeCreate {
        strategy.PrepareForCreate {
            dropDisabledFields
        }
        strategy.Validate
        strategy.Canonicalize
    }
    createValidation (validating webhooks)
    storage Create
    cleanup
    AfterCreate
        Rollback allocations on error
    Decorator
}
```

This same fix pattern will be applied to Delete and Update in subsequent
commits.
2021-09-11 10:51:45 -07:00