k0s icon indicating copy to clipboard operation
k0s copied to clipboard

Context in structs

Open jnummelin opened this issue 2 years ago • 28 comments

Prompted by discussion in https://github.com/k0sproject/k0s/pull/3406#pullrequestreview-1617279953

We have few structs which uses Context in structs which is bit of a bad pattern.

Essentially we have the root signal aware context which is the root context for everything which we need to convey to all the components. We need to figure out a way to do that without storing the context in structs.

jnummelin avatar Sep 22 '23 09:09 jnummelin

  • [ ] https://github.com/k0sproject/k0s/blob/main/inttest/common/footloosesuite.go#L113
  • [ ] https://github.com/k0sproject/k0s/blob/main/pkg/component/controller/kine.go#L50
  • [ ] https://github.com/k0sproject/k0s/blob/main/pkg/component/controller/etcd.go#L58
  • [ ] https://github.com/k0sproject/k0s/blob/main/pkg/component/worker/certificate_manager.go#L38
  • [ ] https://github.com/k0sproject/k0s/blob/main/pkg/leaderelection/lease_pool.go#L53
  • [ ] https://github.com/k0sproject/k0s/blob/main/pkg/autopilot/controller/updates/updater.go#L39

kke avatar Sep 22 '23 11:09 kke

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Oct 22 '23 23:10 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Nov 22 '23 23:11 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Dec 23 '23 23:12 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Jan 24 '24 23:01 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Feb 24 '24 23:02 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Mar 26 '24 23:03 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Apr 26 '24 23:04 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar May 27 '24 23:05 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Jun 27 '24 23:06 github-actions[bot]

There's also a linter for that:

diff --git a/.golangci.yml b/.golangci.yml
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -10,11 +10,12 @@ run:
 
 linters:
   enable:
-    - depguard  # Checks if package imports are in a list of acceptable packages
-    - errorlint # Find code that will cause problems with Go's error wrapping scheme
-    - gofmt     # Checks whether code was gofmt-ed
-    - goheader  # Checks is file headers matche a given pattern
-    - revive    # Stricter drop-in replacement for golint
+    - containedctx # Detects structs containing context.Context fields
+    - depguard     # Checks if package imports are in a list of acceptable packages
+    - errorlint    # Find code that will cause problems with Go's error wrapping scheme
+    - gofmt        # Checks whether code was gofmt-ed
+    - goheader     # Checks is file headers matche a given pattern
+    - revive       # Stricter drop-in replacement for golint
 
 linters-settings:
   depguard:

twz123 avatar Jul 10 '24 14:07 twz123

The contexts in the autopilot structs may be harder to kill, as they are using this external cron library, which has some interfaces to be satisfied that can't be modified with an additional context parameter.

twz123 avatar Jul 10 '24 14:07 twz123

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Aug 09 '24 23:08 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Sep 20 '24 23:09 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Oct 21 '24 23:10 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Nov 22 '24 23:11 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Dec 23 '24 23:12 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Jan 23 '25 23:01 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Feb 23 '25 23:02 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Mar 27 '25 23:03 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Apr 30 '25 23:04 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar May 31 '25 23:05 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Jul 01 '25 23:07 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Aug 01 '25 23:08 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Sep 02 '25 23:09 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Oct 12 '25 23:10 github-actions[bot]

The issue is marked as stale since no activity has been recorded in 30 days

github-actions[bot] avatar Nov 12 '25 23:11 github-actions[bot]