Commit Graph

429 Commits

Author SHA1 Message Date
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
Tim Hockin
5e7e35ca45 Svc REST: Add stub begin* hooks
These will be used in the next set of commits to de-0layer service REST.
2021-09-11 10:51:09 -07:00
Tim Hockin
f3c7e846f1 Svc REST: Move allocations in Create into funcs
All the logic remains unchanged, just reorganized.  The functions are
imperfect but emphasize the change being made and can be cleaned up
subsequently.

This makes the following steps easier to comprehend.
2021-09-11 10:50:27 -07:00
Tim Hockin
960b36b124 Svc REST: Add a transaction API
This will be used in upcoming commits, but for easier history and review
it is pretty stand-alone.
2021-09-11 10:49:37 -07:00
Tim Hockin
14d0571a5f Svc REST: Don't call validation directly
The validation is called soon after anyway.
2021-09-11 10:49:13 -07:00
Tim Hockin
b76a8c3c40 Svc REST: move allocator methods -> alloc object
Move all allocator-related methods onto the alloc object so it can be
used in either REST layer.  There's an INORDINATE amount of test code
here and I am skeptical that it is all useful.  That's for later
commits.
2021-09-11 10:48:32 -07:00
Tim Hockin
89587b3c6a Svc REST: Encapsulate IP and Port allocator logic
Encapsulate the allocator logic so it can be shared across REST
layers while we stage a series of commits to get rid of one layer.
2021-09-11 10:46:48 -07:00
Tim Hockin
d13c920606 Svc: Move ETP clearing to dropTypeDependentFields
I  am not sure why ExternalTrafficPolicy was different, but this is more
consistent with other field clearing logic.
2021-09-11 10:45:30 -07:00
Kubernetes Prow Robot
85b11ad24e
Merge pull request #104699 from vincepri/generate-name-error
Object creation with generateName should return AlreadyExists instead of a Timeout
2021-09-07 17:41:20 -07:00
Vince Prignano
8a9d61278f Object creation with generateName should return a proper error
Signed-off-by: Vince Prignano <vincepri@vmware.com>
2021-09-04 07:34:32 -07:00
Kubernetes Prow Robot
295a8c1371
Merge pull request #104467 from khenidak/fix-104329
fix 104329: check for headless before trying to release the ClusterIPs
2021-09-02 10:55:39 -07:00
Kubernetes Prow Robot
2a88664ecc
Merge pull request #104652 from MikeSpreitzer/add-resourcde-config
Introduce storagebackend.ConfigForResource
2021-09-02 04:00:10 -07:00
Mike Spreitzer
85bcd243aa Introduce storagebackend.ConfigForResource
This is a Config specialized for a GroupResource.
It will support generating new resource-specific metrics.
2021-09-01 16:54:26 -04:00
Tim Hockin
73503a4936 Fix a small regression in Service updates
Prior to 1.22 a user could change NodePort values within a service
during an update, and the apiserver would allocate values for any that
were not specified.

Consider a YAML like:

```
apiVersion: v1
kind: Service
metadata:
  name: foo
spec:
  type: NodePort
  ports:
  - name: p
    port: 80
  - name: q
    port: 81
  selector:
    app: foo
```

When this is created, nodeport values will be allocated for each port.
Something like:

```
apiVersion: v1
kind: Service
metadata:
  name: foo
spec:
  clusterIP: 10.0.149.11
  type: NodePort
  ports:
  - name: p
    nodePort: 30872
    port: 80
    protocol: TCP
    targetPort: 9376
  - name: q
    nodePort: 31310
    port: 81
    protocol: TCP
    targetPort: 81
  selector:
    app: foo
```

If the user PUTs (kubectl replace) the original YAML, we would see that
`.nodePort = 0`, and allocate new ports.  This was ugly at best.

In 1.22 we fixed this to not allocate new values if we still had the old
values, but instead re-assign them.  Net new ports would still be seen
as `.nodePort = 0` and so new allocations would be made.

This broke a corner case as follows:

Prior to 1.22, the user could PUT this YAML:

```
apiVersion: v1
kind: Service
metadata:
  name: foo
spec:
  type: NodePort
  ports:
  - name: p
    nodePort: 31310 # note this is the `q` value
    port: 80
  - name: q
    # note this nodePort is not specified
    port: 81
  selector:
    app: foo
```

The `p` port would take the `q` port's value.  The `q` port would be
seen as `.nodePort = 0` and a new value allocated.  In 1.22 this results
in an error (duplicate value in `p` and `q`).

This is VERY minor but it is an API regression, which we try to avoid,
and the fix is not too horrible.

This commit adds more robust testing of this logic.
2021-08-30 12:42:17 -07:00
Tim Hockin
75dea6b8bc Service REST: Use DeepCopy() on Create() and fix tests 2021-08-22 11:59:33 -07:00
Khaled (Kal) Henidak
2f9cd08831 fix 104329: check for headless before trying to release the ClusterIPs 2021-08-20 22:03:42 +00:00
Antonio Ojea
0cd75e8fec run hack/update-netparse-cve.sh 2021-08-20 10:42:09 +02:00
Tim Hockin
28de406a37 Allocator renames for clarity
Rename `NewCIDRRange()` to `NewInMemory()`
Rename `NewAllocatorCIDRRange()` to `New()`

Rename `NewPortAllocator()` to `NewInMemory()`
Rename `NewPortAllocatorCustom()` to `New()`
2021-08-15 16:44:12 -07:00
Tim Hockin
907fceb206 Remove unused NewContiguousAllocationMap
This was used at some point in the past and never removed.  We are not
in the business of hosting unused code.
2021-08-15 14:12:14 -07:00
Antonio Ojea
ee7562a2f8 add clusterIP allocator metrics
Add 4 new metrics to the ClusterIP allocators:
- current number of available IPs per Service CIDR
- current number of used IPs per Service CIDR
- total number of allocation per Service CIDR
- total number of allocation errors per ServiceCIDR
2021-08-04 13:14:42 +02:00
Tim Hockin
80dda49ce2 Service: Fix semantics for Update wrt allocations
It is not uncommon for users to Create a Service and not specify things
like ClusterIP and NodePort, which we then allocate for them.  They same
that YAML somewhere and later use it again in an Update, but then it
fails.

That's because we detected them trying to set a ClusterIP from a value
to "", which is not allowed.  If it was just NodePort, they would
actually succeed and reallocate a new port.

After this change, we try to "patch" updates where the user did not
specify those values from the old object.
2021-07-07 17:09:12 -07:00
Tim Hockin
5b787aa184 Clean up testing of AllocateLoadBalancerNodePorts
We only need one "tweak" function, and it should be set automatically in
most cases.
2021-07-06 16:36:51 -07:00
Tim Hockin
eae4a19bd3 Fix small bug with AllocateLoadBalancerNodePorts
If the user specified a port, DO reserve it, even if they asked you not
to allocate new ports.
2021-07-06 16:36:51 -07:00
Andrew Sy Kim
28f3f36505
Promote the ServiceInternalTrafficPolicy field to Beta and on by default (#103462)
* pkg/features: promote the ServiceInternalTrafficPolicy field to Beta and on by default

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>

* pkg/api/service/testing: update Service test fixture functions to set internalTrafficPolicy=Cluster by default

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>

* pkg/apis/core/validation: add more Service validation tests for internalTrafficPolicy

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>

* pkg/registry/core/service/storage: fix failing Service REST storage tests to use internalTrafficPolicy: Cluster

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>

* pkg/registry/core/service/storage: add two test cases for Service REST TestServiceRegistryInternalTrafficPolicyClusterThenLocal and TestServiceRegistryInternalTrafficPolicyLocalThenCluster

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>

* pkg/registry/core/service: update strategy unit tests to expect default
internalTrafficPolicy=Cluster

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>

* pkg/proxy/ipvs: fix unit test Test_EndpointSliceReadyAndTerminatingLocal to use internalTrafficPolicy=Cluster

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>

* pkg/apis/core: update fuzzers to set Service internalTrafficPolicy field

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>

* pkg/api/service/testing: refactor Service test fixtures to use Tweak funcs

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
2021-07-06 06:16:30 -07:00
Hanlin Shi
24592ca989 Update the related tests
1. add AllocateLoadBalancerNodePorts fields in specs for validation test cases
2. update fuzzer
3. in resource quota e2e, allocate node port for loadbalancer type service and
   exceed the node port quota

Signed-off-by: Hanlin Shi <shihanlin9@gmail.com>
2021-07-02 21:58:41 +00:00
Tim Hockin
2b84b49ea9 Service REST test: Remove pointless cleanup 2021-07-01 23:24:29 -07:00
Tim Hockin
ca708fa9ac Service REST test: Fix some names 2021-07-01 23:24:24 -07:00
Tim Hockin
54b6a416fb Service REST test: better IP and port alloc checks 2021-07-01 23:01:36 -07:00
Tim Hockin
43b13840db Service REST test: remove obscure const 2021-07-01 18:26:46 -07:00
Tim Hockin
44eb475b10 Service REST test: remove unused return value 2021-07-01 18:26:45 -07:00
Tim Hockin
d6208606f3 Service REST test: remove pointless scaffolding 2021-07-01 18:26:45 -07:00
Tim Hockin
48e591eba2 Service REST test: remove obsolete setup param 2021-07-01 18:26:45 -07:00
Tim Hockin
a3b05033f6 Move endpoints test-helper funcs to a package 2021-07-01 18:26:45 -07:00
Tim Hockin
012bfaf98d Service REST test: remove last use of "inner"
This required making a more hi-fidelity fake.  That, in turn, required
fixing some tests which were just not correct.
2021-07-01 18:26:45 -07:00
Tim Hockin
22ed090e73 Service REST test: mostly remove tests of "inner"
This test was sometimes using the "inner" REST and sometimes using the
"outer" REST.  This commit changes all but one test to use the outer.
The remaining test needs rework.
2021-07-01 18:26:45 -07:00
Tim Hockin
7e8882d189 Service REST test: Remove pointless scaffolding
These fields don't add much value in actually proving it all works, and
they make the upcoming de-layering hard.
2021-07-01 18:26:45 -07:00
Tim Hockin
175f4f3387 Move service test-helper funcs to a package 2021-07-01 18:26:45 -07:00
Tim Hockin
b1fcbab801 Service REST test: helper funcs for ports, too 2021-07-01 18:26:45 -07:00
Tim Hockin
5f65ba7d76 Service REST test: Use helper funcs to streamline
This makes subsequent changes easier to see.
2021-07-01 18:26:44 -07:00
Tim Hockin
d64bb1b29e Service REST test: always check errors
This will be needed in upcoming changes.
2021-07-01 18:26:44 -07:00
Tim Hockin
d3a0332b6c Service REST test: remove unused fields
These fields are never set, so we can remove them with no change in
behavior.
2021-07-01 18:26:44 -07:00
Tim Hockin
292b1444eb Remove bad test for AllocateLoadBalancerNodePorts
If the gate is open, we should never find nil.
2021-07-01 18:26:44 -07:00
Tim Hockin
0bb280044e Fix typo in IP allocator error 2021-07-01 18:26:44 -07:00
Tim Hockin
5970c4671c Add an IPFamily() method to ipallocator 2021-07-01 18:26:44 -07:00
Tim Hockin
89b633d353 Fix doc comment 2021-07-01 18:26:44 -07:00
Antonio Ojea
fa7b5d86e6 remove duplicate validation on services
The rest api for services was validating that, on updates, both
the old and new service have the same type. That guarantees that
the type is going to be the same after that, thus we don't need
to validate the service type on the old and the new service.
2021-06-25 23:18:56 +02:00
Khaled (Kal) Henidak
2c6bba2936 fix auto upgraded preferDualStack services (in cluster upgrade) 2021-06-22 17:40:21 +00:00
Jordan Liggitt
068e4c55a8 Eliminate parallel and unnecessary embedded etcd instances 2021-06-15 09:53:06 -04:00
Andrew Sy Kim
4d38d21880 apis: remove Service topologyKeys
Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
2021-06-03 22:17:45 -04:00
Jordan Liggitt
8c8a4cf3e4 Add WarningsOnCreate,WarningsOnUpdate 2021-05-18 10:42:36 -04:00
Kevin Delgado
a1fac8cbd9 Server-Side Apply: Status Wiping/Reset Fields
Adds and implements ResetFieldsProvder interface in order to ensure that
the fieldmanager no longer owns fields that get reset before the object
is persisted.

Co-authored-by: Kevin Wiesmueller <kwiesmul@redhat.com>
Co-authored-by: Kevin Delgado <kevindelgado@google.com>
2021-03-10 01:02:18 +00:00
Fangyuan Li
7ed2f1d94d Implements Service Internal Traffic Policy
1. Add API definitions;
2. Add feature gate and drops the field when feature gate is not on;
3. Set default values for the field;
4. Add API Validation
5. add kube-proxy iptables and ipvs implementations
6. add tests
2021-03-07 16:52:59 -08:00
Xudong Liu
72da0b1bb0 Add LoadBalancerClass field in service
KEP-1959: https://github.com/kubernetes/enhancements/tree/master/keps/sig-cloud-provider/1959-service-lb-class-field
2021-03-04 17:11:50 -08:00
Kubernetes Prow Robot
4013bd17c3
Merge pull request #99555 from thockin/dualstack-bugs-from-rest-overhaul
Two small bugs in dual-stack init
2021-03-03 14:41:29 -08:00
Tim Hockin
1e39f6ccf9 Two small bugs in dual-stack init
Imporved testing turned these up:

1) Headless+Selectorless, on a single-stack cluster, policy=PreferDual

Prior to this commit, the result was a single IPFamiliy (because we
checked that the 2nd allocator was present).  This changes that case to
populate both families (we don't care if the allocator exists), which is
the same as RequireDual.

2) ClusterIP, user specifies 2 families but no IPs

Prior to this commit, the policy was inferred to be SingleStack.  This
changes that case to correctly default to RequireDual when 2 families
are present but no IPs.
2021-03-03 09:42:02 -08:00
Supriya Premkumar
e52e5e486c
Adds ineffassign to GO linter script.
Changes:
 - Enables ineffassign check in the verify scripts.
 - Fixes lint errs.
2021-03-03 08:28:10 -08:00
Benjamin Elder
56e092e382 hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
jornshen
1e09a758c5 do some cleanup on TestNormalizeClusterIPs 2021-02-16 00:32:00 +08:00
David Eads
37cc89ed8d finish removal of exportoptions 2021-01-22 13:47:31 -05:00
Tim Hockin
625713008d Make REST Decorator funcs not return error 2021-01-08 11:00:39 -08:00
Lars Ekman
a0e613363a service.spec.AllocateLoadBalancerNodePorts followup 2020-11-24 08:10:43 +01:00
Laszlo Janosi
c970a46bc1
Mixed protocol support for Services with type=LoadBalancer (#94028)
* Mixed protocol support for Services with type=LoadBalancer

KEP: https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/20200103-mixed-protocol-lb.md
Add new feature gate to control the support of mixed protocols in Services with type=LoadBalancer
Add new fields to the ServiceStatus
  Add Ports to the LoadBalancerIngress, so cloud provider implementations can report the status of the requested load balanc
er ports
  Add ServiceCondition to the ServiceStatus so Service controllers can indicate the conditions of the Service

* regenerate conflicting stuff
2020-11-13 13:21:04 -08:00
Lars Ekman
8fca0f9955 Update generated files 2020-11-13 07:42:58 +01:00
Lars Ekman
1f4d852f2f Add service.spec.AllocateLoadBalancerNodePorts 2020-11-13 07:37:22 +01:00
Patrik Cyvoct
d29665cc17
Revert "Merge pull request #92312 from Sh4d1/kep_1860"
This reverts commit ef16faf409, reversing
changes made to 2343b8a68b.
2020-11-11 10:26:53 +01:00
Patrik Cyvoct
7bdf2af648
fix review
Signed-off-by: Patrik Cyvoct <patrik@ptrk.io>
2020-11-07 10:00:51 +01:00
Patrik Cyvoct
0153b96ab8
fix review
Signed-off-by: Patrik Cyvoct <patrik@ptrk.io>
2020-11-07 10:00:27 +01:00
wojtekt
8b98305858 Remove variadic argument from storage interface 2020-11-02 16:08:23 +01:00
Tim Hockin
a4c9330683 Populate ClusterIPs on read
Old stored services will not have the `clusterIPs` field when read back
without this.

This includes some renaming for clarity and expanded comments, and a new
test for default on read.
2020-10-29 20:40:39 -07:00
Tim Hockin
4f8fb1d3ca Wipe some fields on service "type" updates
Service has had a problem since forever:

- User creates a service type=LoadBalancer
- We silently allocate them a NodePort
- User changes type to ClusterIP
- We fail the operation because they did not clear NodePort

They never asked for or used the NodePort!

Dual-stack introduced some dependent fields that get auto-wiped on
updates.  This carries it further.

If you squint, you can see Service as a big, messy discriminated union,
with type as the discriminator. Ignoring fields for non-selected
union-modes seems right.

This introduces the potential for an apply loop. Specifically, we will
accept YAML that we did not previously accept. Apply could see the
field in local YAML and not in the server and repeatedly try to patch it
in. But since that YAML is currently an error, it seems like a very low
risk. Almost nobody actually specifies their own NodePort values.

To mitigate this somewhat, we only auto-wipe on updates. The same YAML
would fail to create. This is a little inconsistent. We could
auto-wipe on create, too, at the risk of more potential impact.

To do this properly, we need to know the old and new values, which means
we can not do it in defaulting or conversion. So we do it in strategy.

This change also adds unit tests and updates e2e tests to rely on and
verify this behavior.
2020-10-28 10:41:26 -07:00
Tim Hockin
c5f3e560e4 Make some methods into non-methods 2020-10-28 10:41:26 -07:00
Khaled Henidak (Kal)
6675eba3ef
dual stack services (#91824)
* api: structure change

* api: defaulting, conversion, and validation

* [FIX] validation: auto remove second ip/family when service changes to SingleStack

* [FIX] api: defaulting, conversion, and validation

* api-server: clusterIPs alloc, printers, storage and strategy

* [FIX] clusterIPs default on read

* alloc: auto remove second ip/family when service changes to SingleStack

* api-server: repair loop handling for clusterIPs

* api-server: force kubernetes default service into single stack

* api-server: tie dualstack feature flag with endpoint feature flag

* controller-manager: feature flag, endpoint, and endpointSlice controllers handling multi family service

* [FIX] controller-manager: feature flag, endpoint, and endpointSlicecontrollers handling multi family service

* kube-proxy: feature-flag, utils, proxier, and meta proxier

* [FIX] kubeproxy: call both proxier at the same time

* kubenet: remove forced pod IP sorting

* kubectl: modify describe to include ClusterIPs, IPFamilies, and IPFamilyPolicy

* e2e: fix tests that depends on IPFamily field AND add dual stack tests

* e2e: fix expected error message for ClusterIP immutability

* add integration tests for dualstack

the third phase of dual stack is a very complex change in the API,
basically it introduces Dual Stack services. Main changes are:

- It pluralizes the Service IPFamily field to IPFamilies,
and removes the singular field.
- It introduces a new field IPFamilyPolicyType that can take
3 values to express the "dual-stack(mad)ness" of the cluster:
SingleStack, PreferDualStack and RequireDualStack
- It pluralizes ClusterIP to ClusterIPs.

The goal is to add coverage to the services API operations,
taking into account the 6 different modes a cluster can have:

- single stack: IP4 or IPv6 (as of today)
- dual stack: IPv4 only, IPv6 only, IPv4 - IPv6, IPv6 - IPv4

* [FIX] add integration tests for dualstack

* generated data

* generated files

Co-authored-by: Antonio Ojea <aojea@redhat.com>
2020-10-26 13:15:59 -07:00
wojtekt
fbd65a265a Pipe newFunc to etcd3 storage layer 2020-09-15 08:19:12 +02:00
Jordan Liggitt
68dd0b7f27 Deflake TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocation 2020-09-03 16:31:03 -04:00
Antonio Ojea
b276b4775f Deflake TestServiceRegistryUpdateDryRun test
The test suite was using a /24 cluster network for the allocator.
The ip allocator, if no ip is specified when creating the cluster,
picks one randomly, that means that we had 1/256 chances of
collision.

The TestServiceRegistryUpdateDryRun was creating a service without
a ClusterIP, the ip allocator assigned one random, and it was
never deleting it. The same test was checking later if one
specific IP was not allocated, not taking into consideration
that the same ip may have allocated to the first Service.

To avoid any randomness, we create the first Service with a specific
IP address.
2020-08-18 22:02:55 +02:00
Kubernetes Prow Robot
2e12311d2e
Merge pull request #91606 from danwinship/service-ipallocator-cleanups
Service IPAllocator cleanups
2020-06-30 00:02:27 -07:00
Mark Janssen
e3a0ca2731 Fix staticcheck failures for pkg/registry/...
Errors from staticcheck:
pkg/registry/autoscaling/horizontalpodautoscaler/storage/storage_test.go:207:7: this value of err is never used (SA4006)
pkg/registry/core/namespace/storage/storage.go:256:5: options.OrphanDependents is deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the "orphan" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both. +optional  (SA1019)
pkg/registry/core/namespace/storage/storage.go:257:11: options.OrphanDependents is deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the "orphan" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both. +optional  (SA1019)
pkg/registry/core/namespace/storage/storage.go:266:5: options.OrphanDependents is deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the "orphan" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both. +optional  (SA1019)
pkg/registry/core/namespace/storage/storage.go:267:11: options.OrphanDependents is deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the "orphan" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both. +optional  (SA1019)
pkg/registry/core/persistentvolumeclaim/storage/storage_test.go:165:2: this value of err is never used (SA4006)
pkg/registry/core/resourcequota/storage/storage_test.go:202:7: this value of err is never used (SA4006)
pkg/registry/core/service/ipallocator/allocator_test.go:338:2: this value of other is never used (SA4006)
pkg/registry/core/service/portallocator/allocator_test.go:199:2: this value of other is never used (SA4006)
pkg/registry/core/service/storage/rest_test.go:1843:2: this value of location is never used (SA4006)
pkg/registry/core/service/storage/rest_test.go:1849:2: this value of location is never used (SA4006)
pkg/registry/core/service/storage/rest_test.go:3174:20: use net.IP.Equal to compare net.IPs, not bytes.Equal (SA1021)
pkg/registry/core/service/storage/rest_test.go:3178:20: use net.IP.Equal to compare net.IPs, not bytes.Equal (SA1021)
pkg/registry/core/service/storage/rest_test.go:3185:20: use net.IP.Equal to compare net.IPs, not bytes.Equal (SA1021)
pkg/registry/core/service/storage/rest_test.go:3189:20: use net.IP.Equal to compare net.IPs, not bytes.Equal (SA1021)
2020-06-21 17:23:42 +02:00
Kubernetes Prow Robot
342bcf55e8
Merge pull request #89937 from aojea/portAllocator2
portAllocator sync local data before allocate
2020-06-18 19:03:10 -07:00
Kubernetes Prow Robot
fbc78f53b7
Merge pull request #91590 from knight42/fix/repair-node-port
fix(service::repair): accept same nodePort with different protocols
2020-06-15 18:14:10 -07:00
knight42
136849728c
address comments 2020-06-13 09:30:20 +08:00
knight42
e0d125b046
fix(service::repair): accept same nodePort with different protocols
Signed-off-by: knight42 <anonymousknight96@gmail.com>
2020-06-10 23:35:07 +08:00
Kubernetes Prow Robot
d01cc01ab4
Merge pull request #91400 from danwinship/ipfamily-validation
service: fix IPFamily validation and defaulting problems
2020-06-08 17:55:18 -07:00
Joe Betz
4c99949ae6 Add GetOptions and ListOptions to storage interface 2020-06-03 10:21:38 -07:00
Dan Winship
f6dcc1c07e Minor tweak to IPv6 service IP allocation
The service allocator skips the "broadcast address" in the service
CIDR, but that concept only applies to IPv4 addressing.
2020-06-01 08:16:18 -04:00
Dan Winship
4a7c86c105 make test a bit more generic 2020-06-01 08:13:27 -04:00
Dan Winship
ddebbfd806 update for APIs being moved to utilnet
Several of the functions in pkg/registry/core/service/ipallocator were
moved to k8s.io/utils/net, but then the original code was never
updated to used to the vendored versions.

(utilnet's version of RangeSize does not have the IPv6 special case
that the original code did, so we need to move that to
NewAllocatorCIDRRange now.)
2020-05-30 17:40:02 -04:00
Clayton Coleman
c6b833ac3c service: fix IPFamily validation and defaulting problems
If the dual-stack flag is enabled and the cluster is single stack IPv6,
the allocator logic for service clusterIP does not properly handle rejecting
a request for an IPv4 family. Return a 422 Invalid on the ipFamily field
when the dual stack flag is on (as it would when it hits beta) and the
cluster is configured for single-stack IPv6.

The family is now defaulted or cleared in BeforeCreate/BeforeUpdate,
and is either inherited from the previous object (if nil or unchanged),
or set to the default strategy's family as necessary. The existing
family defaulting when cluster ip is provided remains in the api
section. We add additonal family defaulting at the time we allocate
the IP to ensure that IPFamily is a consequence of the ClusterIP
and prevent accidental reversion. This defaulting also ensures that
old clients that submit a nil IPFamily for non ClusterIP services
receive a default.

To properly handle validation, make the strategy and the validation code
path condition on which configuration options are passed to service
storage. Move validation and preparation logic inside the strategy where
it belongs. Service validation is now dependent on the configuration of
the server, and as such ValidateConditionService needs to know what the
allowed families are.
2020-05-23 11:08:19 -04:00
Davanum Srinivas
07d88617e5
Run hack/update-vendor.sh
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2020-05-16 07:54:33 -04:00
Davanum Srinivas
442a69c3bd
switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2020-05-16 07:54:27 -04:00
Antonio Ojea
e3df13439a fix service allocation concurrency issues
The service allocator is used to allocate ip addresses for the
Service IP allocator and NodePorts for the Service NodePort
allocator. It uses a bitmap backed by etcd to store the allocation
and tries to allocate the resources directly from the local memory
instead from etcd, that can cause issues in environment with
high concurrency.

It may happen, in deployments with multiple apiservers, that the
resource allocation information is out of sync, this is more
sensible with NodePorts, per example:

1. apiserver A create a service with NodePort X
2. apiserver B deletes the service
3. apiserver A creates the service again

If the allocation data of apiserver A wasn't refreshed with the
deletion of apiserver B, apiserver A fails the allocation because
the data is out of sync. The Repair loops solve the problem later,
but there are some use cases that require to improve the concurrency
in the allocation logic.

We can try to not do the Allocation and Release operations locally,
and try instead to check if the local data is up to date with etcd,
and operate over the most recent version of the data.
2020-04-20 09:50:00 +02:00
Antonio Ojea
cb87793d57 Add unit test to portallocator storage
Add unit test for the portallocator storage based on
the ipallocator ones.

pkg/registry/core/service/ipallocator/storage/storage_test.go
2020-04-20 09:49:59 +02:00
SataQiu
e71f84b1c4 dual-stack: fix the bug that isValidAddress only checks the first IP even a Pod has more than one address
Signed-off-by: SataQiu <1527062125@qq.com>
2020-04-09 16:17:34 +08:00
Kubernetes Prow Robot
b215be875c
Merge pull request #89530 from tklauser/use-bits-onescount
Use OnesCount8 from math/bits to implement countBits
2020-04-02 21:40:13 -07:00
SataQiu
b66fd46cd5 fix the bug that Service clusterIP does not respect specified ipFamily
Signed-off-by: SataQiu <1527062125@qq.com>
2020-03-29 17:19:52 +08:00
Tobias Klauser
811f9d8abf Use OnesCount8 from math/bits to implement countBits
This allows to drop the bitCounts table. Also, bits.OnesCount8 can be
intrinsified to a single instruction on several GOARCHes.
2020-03-26 16:58:48 +01:00
SataQiu
776fa5e76f use utilnet.GetIndexedIP instead of replicating the function locally 2020-03-10 18:03:53 +08:00
Kubernetes Prow Robot
86141c0cce
Merge pull request #88503 from robscott/app-protocol
Adding AppProtocol to Service and Endpoints Ports
2020-02-26 00:20:40 -08:00
Rob Scott
6a33727632
Adding AppProtocol to Service and Endpoints Ports 2020-02-25 17:42:34 -08:00
taesun_lee
d578c02975 Fix pkg/registry typos in some error message, variable names etc
error message : differerence -> difference
comment : Ingresss -> Ingress
comment : ObjeceMeta -> ObjectMeta
test case name meta : selectpor -> selector
variable name : secondaryRegistery -> secondaryRegistry
variable name : autosclaerOut -> autoscalerOut
2020-02-25 15:45:20 +09:00
Mike Danese
3aa59f7f30 generated: run refactor 2020-02-07 18:16:47 -08:00
danielqsj
5bc0e26c19 unify alias of api errors under pkg and staging 2019-12-26 16:42:28 +08:00
Jordan Liggitt
6a1354252d Add unit test for extended ipv4 service IP range 2019-12-22 22:32:42 -05:00
Jordan Liggitt
df4f5c1a30 Revert "remove ipallocator in favor of k/utils net package"
This reverts commit f984b4c7a2.
2019-12-22 22:31:25 -05:00
Jordan Liggitt
bb90f0ff94 Install APIs directly for tests 2019-12-13 11:56:29 -05:00
Jordan Liggitt
36eb250cbb Switch TableGenerator/TableConvertor interfaces to metav1 2019-11-26 13:18:18 -05:00
Roc Chan
c9cf3f5b72 Service Topology implementation
* Implement Service Topology for ipvs and iptables proxier
* Add test files
* API validation
2019-11-15 13:36:43 +08:00
chiehting
193f38beae Fix golint issues in pkg/registry/core/service/storage 2019-11-10 15:34:51 +08:00
Kubernetes Prow Robot
9fa1bc8003
Merge pull request #83422 from yastij/remove-ipallocator
remove ipallocator in favor of k/utils net package
2019-10-22 12:52:13 -07:00
Yassine TIJANI
f984b4c7a2 remove ipallocator in favor of k/utils net package
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>
2019-10-22 18:37:13 +02:00
Ted Yu
0779296bf3 Check error return from snapshot Restore 2019-10-13 10:08:20 -07:00
Khaled Henidak(Kal)
c27e0b029d phase 2: generated items 2019-08-28 16:11:46 +00:00
Khaled Henidak(Kal)
93c06821e6 Phase 2: service and endpoint processing 2019-08-28 15:59:43 +00:00
Khaled Henidak(Kal)
5e8ccda71c phase 2: api types + defaulting + validation + disabled fields handling 2019-08-28 15:59:43 +00:00
Tim Hockin
ec60426793 Add dropDisbledFields() to service 2019-08-22 21:36:39 -07:00
Kubernetes Prow Robot
b581f97009
Merge pull request #81325 from tedyu/etcd-ret-err
Propagate error from NewEtcd
2019-08-16 10:26:09 -07:00
Ted Yu
2374f9ad7c Propagate error from NewEtcd 2019-08-14 16:46:23 -07:00
Ted Yu
87b2a3129b Propagate error from NewREST 2019-08-12 13:55:35 -07:00
wojtekt
ee13be2884 Propagate error from creating cacher and storage decorators up 2019-07-15 20:48:30 +02:00
Khaled Henidak(Kal)
54d42e6a65 types modifications + conversion + conversion testing 2019-07-02 15:39:05 +00:00
wojtekt
a756e20cb5 Update autogenerated files 2019-07-01 15:02:49 +02:00
wojtekt
7497260e54 Move etcd/testing to etcd3/testing 2019-07-01 15:02:49 +02:00
Chao Xu
7bb4a3bace Run deleteValidation at the storage layer so that it will be retried on
conflict.

Adding unit test verify that deleteValidation is retried.

adding e2e test verifying the webhook can intercept configmap and custom
resource deletion, and the existing object is sent via the
admissionreview.OldObject.

update the admission integration test to verify that the existing object
is passed to the deletion admission webhook as oldObject, in case of an
immediate deletion and in case of an update-on-delete.
2019-05-17 09:54:11 -07:00
yue9944882
34c4a6e057 Cherrypicking #66535
validate deletion admission object

backward compatibility: add validation for direct storage delete calls

apply nil validation to existing tests

revert behavior changes in deleteCollection call

fixes validation on wiring graceful deletion

remove nil validation check

continue admission check on not found error
2019-05-17 09:50:16 -07:00
Daniel (Shijun) Qian
5268f69405 fix duplicated imports of k8s code (#77484)
* fix duplicated imports of api/core/v1

* fix duplicated imports of client-go/kubernetes

* fix duplicated imports of rest code

* change import name to more reasonable
2019-05-08 10:12:47 -07:00