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

[master] Rewrite to pass in WaitGroup #1408

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ replace (
require (
github.com/Microsoft/hcsshim v0.8.20
github.com/containerd/continuity v0.1.0
github.com/containerd/go-cni v1.0.2 // indirect
github.com/containerd/imgcrypt v1.1.1 // indirect
github.com/google/go-containerregistry v0.5.0
github.com/google/gopacket v1.1.19
github.com/iamacarpet/go-win64api v0.0.0-20210311141720-fe38760bed28
github.com/k3s-io/helm-controller v0.10.1
github.com/pkg/errors v0.9.1
github.com/rancher/k3s v1.21.1-rc1.0.20210720032452-18bc98f60c26
github.com/rancher/k3s v1.21.1-rc1.0.20210721003634-37fcb61f5ea3
github.com/rancher/wharfie v0.4.1
github.com/rancher/wrangler v0.6.2
github.com/rancher/wrangler-api v0.6.0
Expand All @@ -77,7 +75,7 @@ require (
k8s.io/apiserver v0.21.2
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/cri-api v0.21.2
k8s.io/kubernetes v1.21.2
k8s.io/kubernetes v1.21.3
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
sigs.k8s.io/yaml v1.2.0
)
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuP
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cilium/ebpf v0.0.0-20200702112145-1c8d4c9ef775/go.mod h1:7cR51M8ViRLIdUjrmSXlK9pkrsDlLHbO8jiB8X8JnOc=
github.com/cilium/ebpf v0.4.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs=
github.com/cilium/ebpf v0.5.0 h1:E1KshmrMEtkMP2UjlWzfmUV1owWY+BnbL5FxxuatnrU=
github.com/cilium/ebpf v0.5.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs=
Expand All @@ -145,7 +144,6 @@ github.com/container-storage-interface/spec v1.3.0 h1:wMH4UIoWnK/TXYw8mbcIHgZmB6
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
github.com/containerd/aufs v1.0.0/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU=
github.com/containerd/btrfs v1.0.0/go.mod h1:zMcX3qkXTAi9GI50+0HOeuV8LU2ryCE/V2vG/ZBiTss=
github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340/go.mod h1:s5q4SojHctfxANBDvMeIaIovkq29IP48TKAxnhYRxvo=
github.com/containerd/cgroups v1.0.1 h1:iJnMvco9XGvKUvNQkv88bE4uJXxRQH18efbKo9w5vHQ=
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE=
Expand Down Expand Up @@ -194,7 +192,6 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c=
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
github.com/coreos/go-systemd/v22 v22.3.1 h1:7OO2CXWMYNDdaAzP51t4lCCZWwpQHmvPbm9sxWjm3So=
github.com/coreos/go-systemd/v22 v22.3.1/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down Expand Up @@ -813,8 +810,8 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
github.com/quobyte/api v0.1.8/go.mod h1:jL7lIHrmqQ7yh05OJ+eEEdHr0u/kmT1Ff9iHd+4H6VI=
github.com/rancher/dynamiclistener v0.2.3 h1:FHn0Gkx+kIUqsFs3zMMR2QC9ufH/AoBLqO5zH5hbtqw=
github.com/rancher/dynamiclistener v0.2.3/go.mod h1:9WusTANoiRr8cDWCTtf5txieulezHbpv4vhLADPp0zU=
github.com/rancher/k3s v1.21.1-rc1.0.20210720032452-18bc98f60c26 h1:ZJ2GmdAQlRGpc3ytrRKRGwwRSP7j6+x1y54OcflgJX8=
github.com/rancher/k3s v1.21.1-rc1.0.20210720032452-18bc98f60c26/go.mod h1:/H5X29SqehWqW7OSPoli3Wv1VHhuDws+3E/dxRdewH4=
github.com/rancher/k3s v1.21.1-rc1.0.20210721003634-37fcb61f5ea3 h1:ITL6lnEmxXNMoDcCKg3hd/4bGOzZyGwOiIk/xvthBcw=
github.com/rancher/k3s v1.21.1-rc1.0.20210721003634-37fcb61f5ea3/go.mod h1:DVk8Oq7UulWUQ2GJCTvqXKHgkzDXxoDv8ZVtHbhguUc=
github.com/rancher/moq v0.0.0-20190404221404-ee5226d43009/go.mod h1:wpITyDPTi/Na5h73XkbuEf2AP9fbgrIGqqxVzFhYD6U=
github.com/rancher/remotedialer v0.2.0 h1:xD7t3K6JYwTdAsxmGtTHQMkEkFgKouQ1foLxVW424Dc=
github.com/rancher/remotedialer v0.2.0/go.mod h1:tkU8ZvrR5lRgaKWaX71nAy6daeqvPFx/lJEnbW7tXSI=
Expand Down Expand Up @@ -1145,7 +1142,6 @@ golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200120151820-655fe14d7479/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
5 changes: 3 additions & 2 deletions pkg/rke2/clusterrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rke2
import (
"context"
"fmt"
"sync"

"github.com/rancher/k3s/pkg/cli/cmds"
"github.com/sirupsen/logrus"
Expand All @@ -14,9 +15,9 @@ import (
// setClusterRoles applies common clusterroles and clusterrolebindings that are critical
// to the function of internal controllers.
func setClusterRoles() cmds.StartupHook {
return func(ctx context.Context, args cmds.StartupHookArgs) error {
return func(ctx context.Context, wg *sync.WaitGroup, args cmds.StartupHookArgs) error {
go func() {
defer args.Wg.Done()
defer wg.Done()
<-args.APIServerReady
logrus.Info("Applying Cluster Role Bindings")

Expand Down
8 changes: 4 additions & 4 deletions pkg/rke2/kp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package rke2

import (
"context"
"sync"

"github.com/k3s-io/helm-controller/pkg/generated/controllers/helm.cattle.io"
"github.com/rancher/k3s/pkg/cli/cmds"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -16,10 +16,10 @@ const kubeProxyChart = "rke2-kube-proxy"

// setKubeProxyDisabled determines if a cluster already has kube proxy deployed as a chart, if so
// disables running kubeproxy as a static pod.
func setKubeProxyDisabled(clx *cli.Context, cfg *cmds.Server) cmds.StartupHook {
return func(ctx context.Context, args cmds.StartupHookArgs) error {
func setKubeProxyDisabled(cfg *cmds.Server) cmds.StartupHook {
return func(ctx context.Context, wg *sync.WaitGroup, args cmds.StartupHookArgs) error {
go func() {
defer args.Wg.Done()
defer wg.Done()
<-args.APIServerReady
logrus.Info("Checking for kube proxy as a chart")

Expand Down
7 changes: 4 additions & 3 deletions pkg/rke2/np.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rke2
import (
"context"
"fmt"
"sync"

"github.com/rancher/k3s/pkg/cli/cmds"

Expand Down Expand Up @@ -174,17 +175,17 @@ func setNetworkDNSPolicy(ctx context.Context, cs *kubernetes.Clientset) error {

// setNetworkPolicies applies a default network policy across the 3 primary namespaces.
func setNetworkPolicies(cisMode bool, namespaces []string) cmds.StartupHook {
return func(ctx context.Context, args cmds.StartupHookArgs) error {
return func(ctx context.Context, wg *sync.WaitGroup, args cmds.StartupHookArgs) error {
// check if we're running in CIS mode and if so,
// apply the network policy.
if !cisMode {
args.Wg.Done()
wg.Done()
return nil
}

logrus.Info("Applying network policies...")
go func() {
defer args.Wg.Done()
defer wg.Done()
<-args.APIServerReady
cs, err := newClient(args.KubeConfigAdmin, nil)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/rke2/psp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"sync"
"time"

"github.com/rancher/k3s/pkg/cli/cmds"
Expand Down Expand Up @@ -156,9 +157,9 @@ func setSystemUnrestricted(ctx context.Context, cs *kubernetes.Clientset, ns *v1
// if it doesn't, create it. Check if the associated role and bindings exist and
// if they do, delete them.
func setPSPs(cisMode bool) cmds.StartupHook {
return func(ctx context.Context, args cmds.StartupHookArgs) error {
return func(ctx context.Context, wg *sync.WaitGroup, args cmds.StartupHookArgs) error {
go func() {
defer args.Wg.Done()
defer wg.Done()
<-args.APIServerReady
logrus.Info("Applying Pod Security Policies")

Expand Down
2 changes: 1 addition & 1 deletion pkg/rke2/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Server(clx *cli.Context, cfg Config) error {
setNetworkPolicies(cisMode, defaultNamespaces),
setClusterRoles(),
restrictServiceAccounts(cisMode, defaultNamespaces),
setKubeProxyDisabled(clx, &cmds.ServerConfig),
setKubeProxyDisabled(&cmds.ServerConfig),
)

var leaderControllers rawServer.CustomControllers
Expand Down
7 changes: 4 additions & 3 deletions pkg/rke2/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rke2

import (
"context"
"sync"
"time"

"github.com/rancher/k3s/pkg/cli/cmds"
Expand Down Expand Up @@ -63,15 +64,15 @@ func restrictServiceAccount(ctx context.Context, namespace string, cs kubernetes

// restrictServiceAccounts disables automount across the 3 primary namespaces.
func restrictServiceAccounts(cisMode bool, namespaces []string) cmds.StartupHook {
return func(ctx context.Context, args cmds.StartupHookArgs) error {
return func(ctx context.Context, wg *sync.WaitGroup, args cmds.StartupHookArgs) error {
if !cisMode {
args.Wg.Done()
wg.Done()
return nil
}

logrus.Info("Restricting automount...")
go func() {
defer args.Wg.Done()
defer wg.Done()
<-args.APIServerReady
cs, err := newClient(args.KubeConfigAdmin, nil)
if err != nil {
Expand Down