998 Commits

Author SHA1 Message Date
Pires
9affe97f88 Merge pull request #943 from pires/chore/bump_k8s
e2e: test with Kubernetes to 1.20.1
2021-01-10 23:40:10 +00:00
Pires
9e522952c3 e2e: test with Kubernetes to 1.20.1
Signed-off-by: Pires <pjpires@gmail.com>
2021-01-10 17:11:53 +00:00
Pires
99ad66814b build: use Go 1.15
Signed-off-by: Pires <pjpires@gmail.com>
2021-01-10 16:41:31 +00:00
Brian Goff
9745a6a9bc Merge pull request #939 from sargun/fix-name
Fix key name in log entry
2021-01-08 10:43:50 -08:00
Sargun Dhillon
3830b0ed79 Fix key name in log entry 2021-01-08 01:00:22 -08:00
Sargun Dhillon
1b8597647b Refactor queue code
This refactor is a preparation for another commit. I want to add instrumentation
around our queues. The code of how queues were handled was spread throughout
the code base, and that made adding such instrumentation nice and complicated.

This centralizes the queue management logic in queue.go, and only requires
the user to provide a (custom) rate limiter, if they want to, a name,
and a handler.

The lease code is moved into its own package to simplify testing, because
the goroutine leak tester was triggering incorrectly if other tests
were running, and it was measuring leaks from those tests.

This also identified buggy behaviour:

wq := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter(), "test")
wq.AddRateLimited("hi")
fmt.Printf("Added hi, len: %d\n", wq.Len())

wq.Forget("hi")
fmt.Printf("Forgot hi, len: %d\n", wq.Len())

wq.Done("hi")
fmt.Printf("Done hi, len: %d\n", wq.Len())

---
Prints all 0s because event non-delayed items are delayed. If you call Add
directly, then the last line prints a len of 2.

// Workqueue docs:
// Forget indicates that an item is finished being retried.  Doesn't matter whether it's for perm failing
// or for success, we'll stop the rate limiter from tracking it.  This only clears the `rateLimiter`, you
// still have to call `Done` on the queue.

^----- Even this seems untrue
2021-01-08 00:56:05 -08:00
Sargun Dhillon
735eb34829 This adds the v1 lease controller
This refactors the v1 lease controller. It makes two functional differences
to the lease controller:
* It no longer ties lease updates to node pings or node status updates
* There is no fallback mechanism to status updates

This also moves vk_envtest, allowing for future brown-box testing of the
lease controller with envtest
2021-01-05 11:40:44 -08:00
Chris Aniszczyk
8affa1c42a Add CodeQL Security Scanning
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Signed-off-by: Sargun Dhillon <sargun@sargun.me>
2020-12-14 20:13:40 -08:00
Brian Goff
076b28d2b5 Merge pull request #902 from sargun/fix-899
Fix issue #899: Pod status out of sync
2020-12-07 17:14:52 -08:00
Sargun Dhillon
de7f7dd173 Fix issue #899: Pod status out of sync after being marked as not ready by controller manager
As described in the issue, if the following sequence happens, we fail to properly
update the pod status in api server:

1. Create pod in k8s
2. Provider creates the pod and syncs its status back
3. Pod in k8s ready/running, all fine
4. Virtual kubelet fails to update node status for some time for whatever reason (e.g. network connectivity issues)
5. Virtual node marked as NotReady with message: Kubelet stopped posting node status
6. kube-controller-manager of k8s, goes and marks all pods as Ready = false:
7. Virtual kubelet never sync's status of pod in provider back to k8s
2020-12-07 16:50:00 -08:00
Sargun Dhillon
0d1f6f1625 Add Stutter linter
This also adds a bunch of nolints for the node package which
has a ton of stuttering. Perhaps something to mitigate in another
iteration.
2020-12-07 08:51:57 -08:00
Sargun Dhillon
d29adf5ce3 Add Gocritic
This also fixes the issues laid out by gocritic
2020-12-06 13:20:03 -08:00
Sargun Dhillon
ffbfe19e78 Add tests for opencensus (logger) fields 2020-12-06 13:20:03 -08:00
Sargun Dhillon
9a60ea2494 Switch to using Makefile for lint
This uses gobin in the Makefile for golint. Gobin allows for easier
pinning of dependencies that are project specific, as in the actual
gobin command invocation you can specify the version.
2020-12-06 13:20:03 -08:00
Sargun Dhillon
c0d5809285 Add nolintlint to warn us of extraneous nolint comments 2020-12-05 10:59:10 -08:00
Sargun Dhillon
bbe4551940 Fix linter exemptions in golint
We were having issues with golint not properly reporting declaration of functions
without proper documentation (comments). This is due to a config with golangci.

See: https://github.com/golangci/golangci-lint/issues/456
2020-12-05 10:59:10 -08:00
Sargun Dhillon
ca84620958 Fix gosimple check
We were doing a select without needing to.
2020-12-04 13:21:37 -08:00
Brian Goff
4fd2b754b5 Merge pull request #923 from sargun/fix-linter
Enable all linters by default
2020-12-04 10:50:28 -08:00
Sargun Dhillon
52e823a2c1 Merge pull request #913 from sargun/refactor-node-ping-controller
Refactor node ping controller
2020-12-04 00:25:21 -08:00
Sargun Dhillon
11c63bca6f Refactor the way that the that node_ping_controller works
This moves node ping controller to using the new internal lock
API.

The reason for this is twofold:
* The channel approach that was used to notify other
  controllers of changes could only be used once (at startup),
  and couldn't be used in the future to broadcast node
  ping status. The idea idea is here that we could move
  to a sync.Cond style API and only wakeup other controllers
  on change, as opposed to constantly polling each other
* The problem with sync.Cond is that it's not context friendly.
  If we want to do stuff like wait on a sync.cond and use a context
  or a timer or similar, it doesn't work whereas this API allows
  context cancellations on condition change.

The idea is that as we have more controllers that act as centralized
sources of authority, they can broadcast out their state.
2020-12-03 11:40:01 -08:00
Sargun Dhillon
d64d427ec8 Enable all linters by default
This removes the directive from .golangci.yml to disable all linters,
and fixes the relevant bugs / issues that are exposed.
2020-12-03 11:33:06 -08:00
Sargun Dhillon
d562b71d9a Merge pull request #874 from cwdsuzhou/master
Allow to update pod status in K8s if it is deleting in Provider
2020-11-24 01:09:07 -08:00
wadecai
966a960eef Allow to delete pod in K8s if it is deleting in Provider
For example:
Provier is a K8s provider, pod created by deployment would be evicted when node is not ready.
If we do not delete pod in K8s, deployment would not create a new one.

Add some tests for updateStatus
2020-11-24 15:04:25 +08:00
Brian Goff
9454f1fde8 Merge pull request #919 from sargun/configure-logging-for-envtest
In envtest, configure the logger correctly
2020-11-19 15:43:23 -08:00
Sargun Dhillon
8812427117 In envtest, configure the logger correctly
This configures the global logger the same as the local logger,
and adds the test name. It also uses the logger with the test
context as the context logger.
2020-11-17 23:28:59 -08:00
Sargun Dhillon
331a13f514 Merge pull request #898 from turkenh/retry-if-failed
Don't skip pods status update if provider failed once but recovered with retry
2020-11-16 14:11:17 -08:00
Hasan Turken
42f7c56d32 Don't skip pods status update if podStatusReasonProviderFailed
Closes #399

Signed-off-by: Hasan Turken <turkenh@gmail.com>
2020-11-16 13:57:48 -08:00
Brian Goff
7af4ea5b0a Merge pull request #916 from sargun/add-useful-envtests
Add useful envtests
2020-11-16 12:07:11 -08:00
Sargun Dhillon
5bef4ea63b Add some more envtests
This tests if the lease is created
2020-11-16 11:56:01 -08:00
Brian Goff
84a2528741 Merge pull request #914 from sargun/simpler-envtest
Do not export KUBEBUILDER_ASSETS variable
2020-11-16 11:46:01 -08:00
Sargun Dhillon
1a2c0bb029 Do not export KUBEBUILDER_ASSETS variable
This sets KUBEBUILDERA_ASSETS only for envtest. No need to leak
the variable throughout the tests. In addition, it makes it easier
to figure out how to run the tests yourself on command line.
2020-11-16 11:11:52 -08:00
Brian Goff
93d9a5c9f8 Merge pull request #915 from sargun/add-fmt-target
Add fmt target
2020-11-16 10:43:41 -08:00
Brian Goff
4d271c5b53 Merge pull request #918 from sargun/remove-q
Remove $Q Makefile command surpression
2020-11-16 10:42:00 -08:00
Sargun Dhillon
258e809721 Remove $Q Makefile command surpression
The whole $Q thing is unintuitive and that's not how Makefiles
typically act. It's confusing.
2020-11-16 10:30:30 -08:00
Sargun Dhillon
0b946848ee Add fmt target
This adds a target that allows the users to run goimports
across the entire repo.
2020-11-16 03:49:02 -08:00
Sargun Dhillon
79d2ef1f12 Merge pull request #910 from sargun/fix-env-empty-env-var-2
Fix empty environment variables
2020-11-13 11:43:27 -08:00
Sargun Dhillon
21ffe6f0ae Merge pull request #905 from sargun/fix-env-empty-env-var-2
Refactor env.go
2020-11-13 10:41:56 -08:00
Sargun Dhillon
af77bc8364 Fix empty environment variables 2020-11-13 10:36:17 -08:00
Sargun Dhillon
9883707707 Split out each of getEnvironmentVariableValueWithValueFrom*
This takes the multiple mechanisms to do getEnvironmentVariableValueWithValueFrom*
and splits them out into their own functions.
2020-11-13 10:29:33 -08:00
Sargun Dhillon
afe0f52689 Split out getEnvironmentVariableValueWithValueFrom
This splits out all of the ValueFrom environment variable derivation
code into its own function: getEnvironmentVariableValueWithValueFrom
2020-11-13 10:29:33 -08:00
Sargun Dhillon
06c089843e Refactor env.go
This copies and pastes the loop that used to exist in

func populateEnvironmentVariables(..) {
	...
	for _, env := range container.Env {
		... <--- This code
	}
}

Into getEnvironmentVariableValue. getEnvironmentVariableValue
returns val, err, where val is a pointer to a string
to indicate optionality.
2020-11-13 10:29:29 -08:00
Brian Goff
affbd27827 Merge pull request #909 from feiskyer/fix-label
Ensure label node.kubernetes.io/exclude-from-external-load-balancers is added to virtual node
2020-11-13 10:14:25 -08:00
Pengfei Ni
5f1a53c580 Ensure label node.kubernetes.io/exclude-from-external-load-balancers is added to virtual node 2020-11-13 13:16:23 +08:00
Brian Goff
05e9aa2858 Merge pull request #870 from sargun/add-envtest
Add envtest
2020-11-12 15:37:23 -08:00
Sargun Dhillon
1c581260d5 Add envtest
I know it's not an impressive test. It just brings up a node, and
makes sure it registers. Let's do more in the future.

Signed-off-by: Sargun Dhillon <sargun@sargun.me>
2020-11-06 20:37:35 -08:00
Sargun Dhillon
cd68e70627 Merge pull request #904 from sargun/upgrade-golint-to-v1.32.2
Upgrade golint to v1.32.2
2020-11-06 17:24:36 -08:00
Sargun Dhillon
5f63e9d30a Upgrade to golangci-lint v1.32.2 2020-11-06 17:09:47 -08:00
Sargun Dhillon
544cca975f Fix error handling behaviour in nodeutil
Golang Lint v1.32.2 detects this case:
node/nodeutil/client.go:28:12: ineffectual assignment to `err` (ineffassign)
			config, err = rest.InClusterConfig()
			        ^
node/nodeutil/client.go:30:12: ineffectual assignment to `err` (ineffassign)
			config, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
			        ^
2020-11-06 17:09:47 -08:00
Sargun Dhillon
b4e62a645b Revert "Upgrade to golangci-lint v1.32.2" 2020-11-06 17:08:38 -08:00
Sargun Dhillon
ba79256b1d Merge pull request #901 from sargun/upgrade-golint-to-v1.32.2
Upgrade to golangci-lint v1.32.2
2020-11-06 17:07:48 -08:00