Unverified Commit 4cbe0091 authored by Brad Davidson's avatar Brad Davidson Committed by GitHub

Merge pull request #11931 from brandond/2025-03-backports_release-1.29

[release-1.29] Backports for 2025-03
parents 6873bccf 946427bd
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"io" "io"
"io/fs" "io/fs"
"os" "os"
...@@ -20,7 +21,7 @@ import ( ...@@ -20,7 +21,7 @@ import (
"github.com/k3s-io/k3s/pkg/flock" "github.com/k3s-io/k3s/pkg/flock"
"github.com/k3s-io/k3s/pkg/untar" "github.com/k3s-io/k3s/pkg/untar"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/wrangler/pkg/resolvehome" "github.com/rancher/wrangler/pkg/resolvehome"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/pflag" "github.com/spf13/pflag"
...@@ -207,7 +208,7 @@ func stageAndRunCLI(cli *cli.Context, cmd string, dataDir string, args []string) ...@@ -207,7 +208,7 @@ func stageAndRunCLI(cli *cli.Context, cmd string, dataDir string, args []string)
func stageAndRun(dataDir, cmd string, args []string, calledAsInternal bool) error { func stageAndRun(dataDir, cmd string, args []string, calledAsInternal bool) error {
dir, err := extract(dataDir) dir, err := extract(dataDir)
if err != nil { if err != nil {
return errors.Wrap(err, "extracting data") return pkgerrors.WithMessage(err, "extracting data")
} }
logrus.Debugf("Asset dir %s", dir) logrus.Debugf("Asset dir %s", dir)
......
...@@ -7,14 +7,14 @@ import ( ...@@ -7,14 +7,14 @@ import (
"os" "os"
"syscall" "syscall"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
) )
const programPostfix = "" const programPostfix = ""
func runExec(cmd string, args []string, calledAsInternal bool) (err error) { func runExec(cmd string, args []string, calledAsInternal bool) (err error) {
if err := syscall.Exec(cmd, args, os.Environ()); err != nil { if err := syscall.Exec(cmd, args, os.Environ()); err != nil {
return errors.Wrapf(err, "exec %s failed", cmd) return pkgerrors.WithMessagef(err, "exec %s failed", cmd)
} }
return nil return nil
} }
...@@ -386,10 +386,10 @@ fi ...@@ -386,10 +386,10 @@ fi
flags=" flags="
NAMESPACES NET_NS PID_NS IPC_NS UTS_NS NAMESPACES NET_NS PID_NS IPC_NS UTS_NS
CGROUPS CGROUP_PIDS CGROUP_CPUACCT CGROUP_DEVICE CGROUP_FREEZER CGROUP_SCHED CPUSETS MEMCG CGROUPS CGROUP_PIDS CGROUP_CPUACCT CGROUP_DEVICE CGROUP_FREEZER CGROUP_SCHED CPUSETS MEMCG
KEYS SECCOMP KEYS
VETH BRIDGE BRIDGE_NETFILTER VETH BRIDGE BRIDGE_NETFILTER
IP_NF_FILTER IP_NF_TARGET_MASQUERADE IP_NF_TARGET_REJECT IP_NF_FILTER IP_NF_TARGET_MASQUERADE IP_NF_TARGET_REJECT
NETFILTER_XT_MATCH_ADDRTYPE NETFILTER_XT_MATCH_CONNTRACK NETFILTER_XT_MATCH_IPVS NETFILTER_XT_MATCH_COMMENT NETFILTER_XT_MATCH_MULTIPORT NETFILTER_XT_MATCH_ADDRTYPE NETFILTER_XT_MATCH_CONNTRACK NETFILTER_XT_MATCH_IPVS NETFILTER_XT_MATCH_COMMENT NETFILTER_XT_MATCH_MULTIPORT NETFILTER_XT_MATCH_STATISTIC
IP_NF_NAT NF_NAT IP_NF_NAT NF_NAT
POSIX_MQUEUE POSIX_MQUEUE
" "
...@@ -406,9 +406,6 @@ echo 'Optional Features:' ...@@ -406,9 +406,6 @@ echo 'Optional Features:'
check_flags USER_NS check_flags USER_NS
check_distro_userns check_distro_userns
} }
{
check_flags SECCOMP
}
# { # {
# check_flags MEMCG_SWAP MEMCG_SWAP_ENABLED # check_flags MEMCG_SWAP MEMCG_SWAP_ENABLED
# if [ -e /sys/fs/cgroup/memory/memory.memsw.limit_in_bytes ]; then # if [ -e /sys/fs/cgroup/memory/memory.memsw.limit_in_bytes ]; then
......
...@@ -7,7 +7,8 @@ replace ( ...@@ -7,7 +7,8 @@ replace (
github.com/Mirantis/cri-dockerd => github.com/k3s-io/cri-dockerd v0.3.12-k3s1 // k3s/release-1.28 github.com/Mirantis/cri-dockerd => github.com/k3s-io/cri-dockerd v0.3.12-k3s1 // k3s/release-1.28
github.com/cilium/ebpf => github.com/cilium/ebpf v0.12.3 github.com/cilium/ebpf => github.com/cilium/ebpf v0.12.3
github.com/cloudnativelabs/kube-router/v2 => github.com/k3s-io/kube-router/v2 v2.2.1 github.com/cloudnativelabs/kube-router/v2 => github.com/k3s-io/kube-router/v2 v2.2.1
github.com/containerd/containerd => github.com/k3s-io/containerd v1.7.23-k3s2 github.com/containerd/containerd => github.com/k3s-io/containerd v1.7.26-k3s1
github.com/containerd/containerd/api => github.com/containerd/containerd/api v1.8.0
github.com/containerd/imgcrypt => github.com/containerd/imgcrypt v1.1.11 github.com/containerd/imgcrypt => github.com/containerd/imgcrypt v1.1.11
github.com/distribution/reference => github.com/distribution/reference v0.5.0 github.com/distribution/reference => github.com/distribution/reference v0.5.0
github.com/docker/distribution => github.com/docker/distribution v2.8.3+incompatible github.com/docker/distribution => github.com/docker/distribution v2.8.3+incompatible
...@@ -17,21 +18,20 @@ replace ( ...@@ -17,21 +18,20 @@ replace (
github.com/googleapis/gax-go/v2 => github.com/googleapis/gax-go/v2 v2.14.1 github.com/googleapis/gax-go/v2 => github.com/googleapis/gax-go/v2 v2.14.1
github.com/kubernetes-sigs/cri-tools => github.com/k3s-io/cri-tools v1.29.0-k3s1 github.com/kubernetes-sigs/cri-tools => github.com/k3s-io/cri-tools v1.29.0-k3s1
github.com/open-policy-agent/opa => github.com/open-policy-agent/opa v0.59.0 // github.com/Microsoft/hcsshim using bad version v0.42.2 github.com/open-policy-agent/opa => github.com/open-policy-agent/opa v0.59.0 // github.com/Microsoft/hcsshim using bad version v0.42.2
github.com/opencontainers/runc => github.com/k3s-io/runc v1.2.4-k3s1
github.com/opencontainers/selinux => github.com/opencontainers/selinux v1.11.0 github.com/opencontainers/selinux => github.com/opencontainers/selinux v1.11.0
github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.18.0 github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.18.0
github.com/prometheus/common => github.com/prometheus/common v0.45.0 github.com/prometheus/common => github.com/prometheus/common v0.45.0
github.com/rancher/wrangler => github.com/rancher/wrangler v1.1.1-0.20230818201331-3604a6be798d github.com/rancher/wrangler => github.com/rancher/wrangler v1.1.1-0.20230818201331-3604a6be798d
github.com/spegel-org/spegel => github.com/k3s-io/spegel v0.0.30-k3s1.31 github.com/spegel-org/spegel => github.com/k3s-io/spegel v0.0.30-k3s1.31
github.com/ugorji/go => github.com/ugorji/go v1.2.11 github.com/ugorji/go => github.com/ugorji/go v1.2.11
go.etcd.io/etcd/api/v3 => github.com/k3s-io/etcd/api/v3 v3.5.18-k3s1 go.etcd.io/etcd/api/v3 => github.com/k3s-io/etcd/api/v3 v3.5.19-k3s1.30
go.etcd.io/etcd/client/pkg/v3 => github.com/k3s-io/etcd/client/pkg/v3 v3.5.18-k3s1 go.etcd.io/etcd/client/pkg/v3 => github.com/k3s-io/etcd/client/pkg/v3 v3.5.19-k3s1.30
go.etcd.io/etcd/client/v2 => github.com/k3s-io/etcd/client/v2 v2.305.18-k3s1 go.etcd.io/etcd/client/v2 => github.com/k3s-io/etcd/client/v2 v2.305.19-k3s1.30
go.etcd.io/etcd/client/v3 => github.com/k3s-io/etcd/client/v3 v3.5.18-k3s1 go.etcd.io/etcd/client/v3 => github.com/k3s-io/etcd/client/v3 v3.5.19-k3s1.30
go.etcd.io/etcd/etcdutl/v3 => github.com/k3s-io/etcd/etcdutl/v3 v3.5.18-k3s1 go.etcd.io/etcd/etcdutl/v3 => github.com/k3s-io/etcd/etcdutl/v3 v3.5.19-k3s1.30
go.etcd.io/etcd/pkg/v3 => github.com/k3s-io/etcd/pkg/v3 v3.5.18-k3s1 go.etcd.io/etcd/pkg/v3 => github.com/k3s-io/etcd/pkg/v3 v3.5.19-k3s1.30
go.etcd.io/etcd/raft/v3 => github.com/k3s-io/etcd/raft/v3 v3.5.18-k3s1 go.etcd.io/etcd/raft/v3 => github.com/k3s-io/etcd/raft/v3 v3.5.19-k3s1.30
go.etcd.io/etcd/server/v3 => github.com/k3s-io/etcd/server/v3 v3.5.18-k3s1 go.etcd.io/etcd/server/v3 => github.com/k3s-io/etcd/server/v3 v3.5.19-k3s1.30
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful => go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.44.0 go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful => go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.44.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0
golang.org/x/crypto => golang.org/x/crypto v0.17.0 golang.org/x/crypto => golang.org/x/crypto v0.17.0
...@@ -74,6 +74,8 @@ replace ( ...@@ -74,6 +74,8 @@ replace (
k8s.io/sample-apiserver => github.com/k3s-io/kubernetes/staging/src/k8s.io/sample-apiserver v1.29.14-k3s1 k8s.io/sample-apiserver => github.com/k3s-io/kubernetes/staging/src/k8s.io/sample-apiserver v1.29.14-k3s1
k8s.io/sample-cli-plugin => github.com/k3s-io/kubernetes/staging/src/k8s.io/sample-cli-plugin v1.29.14-k3s1 k8s.io/sample-cli-plugin => github.com/k3s-io/kubernetes/staging/src/k8s.io/sample-cli-plugin v1.29.14-k3s1
k8s.io/sample-controller => github.com/k3s-io/kubernetes/staging/src/k8s.io/sample-controller v1.29.14-k3s1 k8s.io/sample-controller => github.com/k3s-io/kubernetes/staging/src/k8s.io/sample-controller v1.29.14-k3s1
sigs.k8s.io/json => sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
sigs.k8s.io/structured-merge-diff/v4 => sigs.k8s.io/structured-merge-diff/v4 v4.4.1
sourcegraph.com/sourcegraph/go-diff => github.com/sourcegraph/go-diff v0.6.0 sourcegraph.com/sourcegraph/go-diff => github.com/sourcegraph/go-diff v0.6.0
) )
...@@ -109,6 +111,7 @@ require ( ...@@ -109,6 +111,7 @@ require (
github.com/ipfs/go-log/v2 v2.5.1 github.com/ipfs/go-log/v2 v2.5.1
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
github.com/json-iterator/go v1.1.12 github.com/json-iterator/go v1.1.12
github.com/k3s-io/api v0.1.0-k3s1.29
github.com/k3s-io/helm-controller v0.15.16 github.com/k3s-io/helm-controller v0.15.16
github.com/k3s-io/kine v0.13.9 github.com/k3s-io/kine v0.13.9
github.com/klauspost/compress v1.17.11 github.com/klauspost/compress v1.17.11
...@@ -119,8 +122,8 @@ require ( ...@@ -119,8 +122,8 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/onsi/ginkgo/v2 v2.22.0 github.com/onsi/ginkgo/v2 v2.22.0
github.com/onsi/gomega v1.34.2 github.com/onsi/gomega v1.34.2
github.com/opencontainers/runc v1.1.12 github.com/opencontainers/runc v1.2.5
github.com/opencontainers/selinux v1.11.0 github.com/opencontainers/selinux v1.11.1
github.com/otiai10/copy v1.7.0 github.com/otiai10/copy v1.7.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.5 github.com/prometheus/client_golang v1.20.5
...@@ -140,17 +143,17 @@ require ( ...@@ -140,17 +143,17 @@ require (
github.com/urfave/cli v1.22.15 github.com/urfave/cli v1.22.15
github.com/vishvananda/netlink v1.3.0 github.com/vishvananda/netlink v1.3.0
github.com/yl2chen/cidranger v1.0.2 github.com/yl2chen/cidranger v1.0.2
go.etcd.io/etcd/api/v3 v3.5.18 go.etcd.io/etcd/api/v3 v3.5.19
go.etcd.io/etcd/client/pkg/v3 v3.5.18 go.etcd.io/etcd/client/pkg/v3 v3.5.19
go.etcd.io/etcd/client/v3 v3.5.18 go.etcd.io/etcd/client/v3 v3.5.19
go.etcd.io/etcd/etcdutl/v3 v3.5.18 go.etcd.io/etcd/etcdutl/v3 v3.5.18
go.etcd.io/etcd/server/v3 v3.5.18 go.etcd.io/etcd/server/v3 v3.5.19
go.uber.org/zap v1.27.0 go.uber.org/zap v1.27.0
golang.org/x/crypto v0.32.0 golang.org/x/crypto v0.35.0
golang.org/x/mod v0.22.0 golang.org/x/mod v0.22.0
golang.org/x/net v0.34.0 golang.org/x/net v0.36.0
golang.org/x/sync v0.10.0 golang.org/x/sync v0.11.0
golang.org/x/sys v0.29.0 golang.org/x/sys v0.30.0
google.golang.org/grpc v1.70.0 google.golang.org/grpc v1.70.0
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.31.5 k8s.io/api v0.31.5
...@@ -222,19 +225,19 @@ require ( ...@@ -222,19 +225,19 @@ require (
github.com/containerd/go-runc v1.1.0 // indirect github.com/containerd/go-runc v1.1.0 // indirect
github.com/containerd/imgcrypt v1.2.0-rc1 // indirect github.com/containerd/imgcrypt v1.2.0-rc1 // indirect
github.com/containerd/log v0.1.0 // indirect github.com/containerd/log v0.1.0 // indirect
github.com/containerd/nri v0.6.1 // indirect github.com/containerd/nri v0.8.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect github.com/containerd/platforms v0.2.1 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
github.com/containerd/ttrpc v1.2.5 // indirect github.com/containerd/ttrpc v1.2.7 // indirect
github.com/containerd/typeurl v1.0.2 // indirect github.com/containerd/typeurl v1.0.2 // indirect
github.com/containerd/typeurl/v2 v2.2.3 // indirect github.com/containerd/typeurl/v2 v2.2.3 // indirect
github.com/containernetworking/cni v1.2.3 // indirect github.com/containernetworking/cni v1.2.3 // indirect
github.com/containernetworking/plugins v1.5.1 // indirect github.com/containernetworking/plugins v1.5.1 // indirect
github.com/containers/ocicrypt v1.2.0 // indirect github.com/containers/ocicrypt v1.2.1 // indirect
github.com/coreos/go-oidc v2.2.1+incompatible // indirect github.com/coreos/go-oidc v2.2.1+incompatible // indirect
github.com/coreos/go-semver v0.3.1 // indirect github.com/coreos/go-semver v0.3.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/cyphar/filepath-securejoin v0.3.5 // indirect github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/danwinship/knftables v0.0.13 // indirect github.com/danwinship/knftables v0.0.13 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/daviddengcn/go-colortext v1.0.0 // indirect github.com/daviddengcn/go-colortext v1.0.0 // indirect
...@@ -263,7 +266,7 @@ require ( ...@@ -263,7 +266,7 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect github.com/go-errors/errors v1.4.2 // indirect
github.com/go-ini/ini v1.67.0 // indirect github.com/go-ini/ini v1.67.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.2 // indirect github.com/go-jose/go-jose/v4 v4.0.4 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect
...@@ -436,6 +439,7 @@ require ( ...@@ -436,6 +439,7 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/seccomp/libseccomp-golang v0.10.0 // indirect github.com/seccomp/libseccomp-golang v0.10.0 // indirect
github.com/shengdoushi/base58 v1.0.0 // indirect github.com/shengdoushi/base58 v1.0.0 // indirect
github.com/smallstep/pkcs7 v0.1.1 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.12.0 // indirect github.com/spf13/afero v1.12.0 // indirect
...@@ -457,10 +461,9 @@ require ( ...@@ -457,10 +461,9 @@ require (
github.com/xlab/treeprint v1.2.0 // indirect github.com/xlab/treeprint v1.2.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.etcd.io/bbolt v1.3.11 // indirect go.etcd.io/bbolt v1.3.11 // indirect
go.etcd.io/etcd/client/v2 v2.305.18 // indirect go.etcd.io/etcd/client/v2 v2.305.19 // indirect
go.etcd.io/etcd/pkg/v3 v3.5.18 // indirect go.etcd.io/etcd/pkg/v3 v3.5.19 // indirect
go.etcd.io/etcd/raft/v3 v3.5.18 // indirect go.etcd.io/etcd/raft/v3 v3.5.19 // indirect
go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1 // indirect
go.opencensus.io v0.24.0 // indirect go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.53.0 // indirect go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.53.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
...@@ -480,7 +483,7 @@ require ( ...@@ -480,7 +483,7 @@ require (
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/oauth2 v0.25.0 // indirect golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/term v0.28.0 // indirect golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.8.0 // indirect golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.28.0 // indirect golang.org/x/tools v0.28.0 // indirect
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173 // indirect golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173 // indirect
...@@ -498,7 +501,6 @@ require ( ...@@ -498,7 +501,6 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.30.0 // indirect k8s.io/apiextensions-apiserver v0.30.0 // indirect
k8s.io/code-generator v0.30.0 // indirect
k8s.io/controller-manager v0.25.4 // indirect k8s.io/controller-manager v0.25.4 // indirect
k8s.io/csi-translation-lib v0.0.0 // indirect k8s.io/csi-translation-lib v0.0.0 // indirect
k8s.io/dynamic-resource-allocation v0.0.0 // indirect k8s.io/dynamic-resource-allocation v0.0.0 // indirect
...@@ -507,7 +509,7 @@ require ( ...@@ -507,7 +509,7 @@ require (
k8s.io/kms v0.0.0 // indirect k8s.io/kms v0.0.0 // indirect
k8s.io/kube-aggregator v0.30.0 // indirect k8s.io/kube-aggregator v0.30.0 // indirect
k8s.io/kube-controller-manager v0.0.0 // indirect k8s.io/kube-controller-manager v0.0.0 // indirect
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 // indirect k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/kube-scheduler v0.0.0 // indirect k8s.io/kube-scheduler v0.0.0 // indirect
k8s.io/kubelet v0.28.6 // indirect k8s.io/kubelet v0.28.6 // indirect
k8s.io/legacy-cloud-providers v0.0.0 // indirect k8s.io/legacy-cloud-providers v0.0.0 // indirect
...@@ -520,7 +522,7 @@ require ( ...@@ -520,7 +522,7 @@ require (
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kustomize/v5 v5.0.4-0.20230601165947-6ce0bf390ce3 // indirect sigs.k8s.io/kustomize/kustomize/v5 v5.0.4-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
tags.cncf.io/container-device-interface v0.8.0 // indirect tags.cncf.io/container-device-interface v0.8.1 // indirect
tags.cncf.io/container-device-interface/specs-go v0.8.0 // indirect tags.cncf.io/container-device-interface/specs-go v0.8.0 // indirect
) )
...@@ -3,8 +3,8 @@ package main ...@@ -3,8 +3,8 @@ package main
import ( import (
"os" "os"
_ "github.com/k3s-io/api/pkg/generated/controllers/k3s.cattle.io/v1"
k3scrd "github.com/k3s-io/k3s/pkg/crd" k3scrd "github.com/k3s-io/k3s/pkg/crd"
_ "github.com/k3s-io/k3s/pkg/generated/controllers/k3s.cattle.io/v1"
"github.com/rancher/wrangler/pkg/crd" "github.com/rancher/wrangler/pkg/crd"
) )
......
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate rm -rf pkg/generated
//go:generate go run pkg/codegen/main.go //go:generate go run pkg/codegen/main.go
//go:generate go fmt pkg/deploy/zz_generated_bindata.go //go:generate go fmt pkg/deploy/zz_generated_bindata.go
//go:generate go fmt pkg/static/zz_generated_bindata.go //go:generate go fmt pkg/static/zz_generated_bindata.go
......
FROM alpine:3.20 as base FROM alpine:3.20 as base
RUN apk add -U ca-certificates zstd tzdata RUN apk add -U ca-certificates zstd tzdata
COPY build/out/data-linux.tar.zst / COPY build/out/data-linux.tar.zst /
RUN mkdir -p /image/etc/ssl/certs /image/run /image/var/run /image/tmp /image/lib/modules /image/lib/firmware && \ RUN mkdir -p /image/etc/ssl/certs /image/run /image/var/run /image/tmp /image/lib/modules /image/lib/firmware /image/var/lib/rancher/k3s/data/cni && \
zstdcat -d /data-linux.tar.zst | tar -xa -C /image && \ zstdcat -d /data-linux.tar.zst | tar -xa -C /image && \
for FILE in cni $(/image/bin/find /image/bin -lname cni -printf "%f\n"); do ln -s /bin/cni /image/var/lib/rancher/k3s/data/cni/$FILE; done && \
echo "root:x:0:0:root:/:/bin/sh" > /image/etc/passwd && \ echo "root:x:0:0:root:/:/bin/sh" > /image/etc/passwd && \
echo "root:x:0:" > /image/etc/group && \ echo "root:x:0:" > /image/etc/group && \
cp /etc/ssl/certs/ca-certificates.crt /image/etc/ssl/certs/ca-certificates.crt cp /etc/ssl/certs/ca-certificates.crt /image/etc/ssl/certs/ca-certificates.crt
...@@ -17,12 +18,12 @@ RUN mkdir -p /etc && \ ...@@ -17,12 +18,12 @@ RUN mkdir -p /etc && \
chmod 1777 /tmp chmod 1777 /tmp
FROM scratch FROM scratch
COPY --from=collect / /
VOLUME /var/lib/kubelet VOLUME /var/lib/kubelet
VOLUME /var/lib/rancher/k3s VOLUME /var/lib/rancher/k3s
VOLUME /var/lib/cni VOLUME /var/lib/cni
VOLUME /var/log VOLUME /var/log
ENV PATH="$PATH:/bin/aux" COPY --from=collect / /
ENV PATH="/var/lib/rancher/k3s/data/cni:$PATH:/bin/aux"
ENV CRI_CONFIG_FILE="/var/lib/rancher/k3s/agent/etc/crictl.yaml" ENV CRI_CONFIG_FILE="/var/lib/rancher/k3s/agent/etc/crictl.yaml"
ENTRYPOINT ["/bin/k3s"] ENTRYPOINT ["/bin/k3s"]
CMD ["agent"] CMD ["agent"]
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"crypto/x509" "crypto/x509"
"encoding/hex" "encoding/hex"
"encoding/pem" "encoding/pem"
"errors"
"fmt" "fmt"
"io" "io"
"net" "net"
...@@ -32,7 +33,7 @@ import ( ...@@ -32,7 +33,7 @@ import (
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/k3s-io/k3s/pkg/vpn" "github.com/k3s-io/k3s/pkg/vpn"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
certutil "github.com/rancher/dynamiclistener/cert" certutil "github.com/rancher/dynamiclistener/cert"
"github.com/rancher/wharfie/pkg/registries" "github.com/rancher/wharfie/pkg/registries"
"github.com/rancher/wrangler/pkg/slice" "github.com/rancher/wrangler/pkg/slice"
...@@ -247,7 +248,7 @@ func upgradeOldNodePasswordPath(oldNodePasswordFile, newNodePasswordFile string) ...@@ -247,7 +248,7 @@ func upgradeOldNodePasswordPath(oldNodePasswordFile, newNodePasswordFile string)
func getKubeletServingCert(nodeName string, nodeIPs []net.IP, certFile, keyFile, nodePasswordFile string, info *clientaccess.Info) error { func getKubeletServingCert(nodeName string, nodeIPs []net.IP, certFile, keyFile, nodePasswordFile string, info *clientaccess.Info) error {
csr, err := getCSRBytes(keyFile) csr, err := getCSRBytes(keyFile)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create certificate request %s", certFile) return pkgerrors.WithMessagef(err, "failed to create certificate request %s", certFile)
} }
basename := filepath.Base(certFile) basename := filepath.Base(certFile)
...@@ -261,11 +262,11 @@ func getKubeletServingCert(nodeName string, nodeIPs []net.IP, certFile, keyFile, ...@@ -261,11 +262,11 @@ func getKubeletServingCert(nodeName string, nodeIPs []net.IP, certFile, keyFile,
// must be used instead of the one we signed the CSR with. // must be used instead of the one we signed the CSR with.
certBytes, keyBytes := splitCertKeyPEM(body) certBytes, keyBytes := splitCertKeyPEM(body)
if err := os.WriteFile(certFile, certBytes, 0600); err != nil { if err := os.WriteFile(certFile, certBytes, 0600); err != nil {
return errors.Wrapf(err, "failed to write cert %s", certFile) return pkgerrors.WithMessagef(err, "failed to write cert %s", certFile)
} }
if len(keyBytes) > 0 { if len(keyBytes) > 0 {
if err := os.WriteFile(keyFile, keyBytes, 0600); err != nil { if err := os.WriteFile(keyFile, keyBytes, 0600); err != nil {
return errors.Wrapf(err, "failed to write key %s", keyFile) return pkgerrors.WithMessagef(err, "failed to write key %s", keyFile)
} }
} }
return nil return nil
...@@ -279,7 +280,7 @@ func getHostFile(filename string, info *clientaccess.Info) error { ...@@ -279,7 +280,7 @@ func getHostFile(filename string, info *clientaccess.Info) error {
return err return err
} }
if err := os.WriteFile(filename, fileBytes, 0600); err != nil { if err := os.WriteFile(filename, fileBytes, 0600); err != nil {
return errors.Wrapf(err, "failed to write cert %s", filename) return pkgerrors.WithMessagef(err, "failed to write cert %s", filename)
} }
return nil return nil
} }
...@@ -291,7 +292,7 @@ func getHostFile(filename string, info *clientaccess.Info) error { ...@@ -291,7 +292,7 @@ func getHostFile(filename string, info *clientaccess.Info) error {
func getClientCert(certFile, keyFile string, info *clientaccess.Info) error { func getClientCert(certFile, keyFile string, info *clientaccess.Info) error {
csr, err := getCSRBytes(keyFile) csr, err := getCSRBytes(keyFile)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create certificate request %s", certFile) return pkgerrors.WithMessagef(err, "failed to create certificate request %s", certFile)
} }
basename := filepath.Base(certFile) basename := filepath.Base(certFile)
...@@ -305,11 +306,11 @@ func getClientCert(certFile, keyFile string, info *clientaccess.Info) error { ...@@ -305,11 +306,11 @@ func getClientCert(certFile, keyFile string, info *clientaccess.Info) error {
// must be used instead of the one we signed the CSR with. // must be used instead of the one we signed the CSR with.
certBytes, keyBytes := splitCertKeyPEM(fileBytes) certBytes, keyBytes := splitCertKeyPEM(fileBytes)
if err := os.WriteFile(certFile, certBytes, 0600); err != nil { if err := os.WriteFile(certFile, certBytes, 0600); err != nil {
return errors.Wrapf(err, "failed to write cert %s", certFile) return pkgerrors.WithMessagef(err, "failed to write cert %s", certFile)
} }
if len(keyBytes) > 0 { if len(keyBytes) > 0 {
if err := os.WriteFile(keyFile, keyBytes, 0600); err != nil { if err := os.WriteFile(keyFile, keyBytes, 0600); err != nil {
return errors.Wrapf(err, "failed to write key %s", keyFile) return pkgerrors.WithMessagef(err, "failed to write key %s", keyFile)
} }
} }
return nil return nil
...@@ -352,7 +353,7 @@ func splitCertKeyPEM(bytes []byte) (certPem []byte, keyPem []byte) { ...@@ -352,7 +353,7 @@ func splitCertKeyPEM(bytes []byte) (certPem []byte, keyPem []byte) {
func getKubeletClientCert(certFile, keyFile, nodeName string, nodeIPs []net.IP, nodePasswordFile string, info *clientaccess.Info) error { func getKubeletClientCert(certFile, keyFile, nodeName string, nodeIPs []net.IP, nodePasswordFile string, info *clientaccess.Info) error {
csr, err := getCSRBytes(keyFile) csr, err := getCSRBytes(keyFile)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create certificate request %s", certFile) return pkgerrors.WithMessagef(err, "failed to create certificate request %s", certFile)
} }
basename := filepath.Base(certFile) basename := filepath.Base(certFile)
...@@ -366,11 +367,11 @@ func getKubeletClientCert(certFile, keyFile, nodeName string, nodeIPs []net.IP, ...@@ -366,11 +367,11 @@ func getKubeletClientCert(certFile, keyFile, nodeName string, nodeIPs []net.IP,
// must be used instead of the one we signed the CSR with. // must be used instead of the one we signed the CSR with.
certBytes, keyBytes := splitCertKeyPEM(body) certBytes, keyBytes := splitCertKeyPEM(body)
if err := os.WriteFile(certFile, certBytes, 0600); err != nil { if err := os.WriteFile(certFile, certBytes, 0600); err != nil {
return errors.Wrapf(err, "failed to write cert %s", certFile) return pkgerrors.WithMessagef(err, "failed to write cert %s", certFile)
} }
if len(keyBytes) > 0 { if len(keyBytes) > 0 {
if err := os.WriteFile(keyFile, keyBytes, 0600); err != nil { if err := os.WriteFile(keyFile, keyBytes, 0600); err != nil {
return errors.Wrapf(err, "failed to write key %s", keyFile) return pkgerrors.WithMessagef(err, "failed to write key %s", keyFile)
} }
} }
return nil return nil
...@@ -437,13 +438,13 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -437,13 +438,13 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
controlConfig, err := getConfig(info) controlConfig, err := getConfig(info)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to retrieve configuration from server") return nil, pkgerrors.WithMessage(err, "failed to retrieve configuration from server")
} }
// If the supervisor and externally-facing apiserver are not on the same port, tell the proxy where to find the apiserver. // If the supervisor and externally-facing apiserver are not on the same port, tell the proxy where to find the apiserver.
if controlConfig.SupervisorPort != controlConfig.HTTPSPort { if controlConfig.SupervisorPort != controlConfig.HTTPSPort {
isIPv6 := utilsnet.IsIPv6(net.ParseIP(util.GetFirstValidIPString(envInfo.NodeIP))) isIPv6 := utilsnet.IsIPv6(net.ParseIP(util.GetFirstValidIPString(envInfo.NodeIP)))
if err := proxy.SetAPIServerPort(controlConfig.HTTPSPort, isIPv6); err != nil { if err := proxy.SetAPIServerPort(controlConfig.HTTPSPort, isIPv6); err != nil {
return nil, errors.Wrapf(err, "failed to set apiserver port to %d", controlConfig.HTTPSPort) return nil, pkgerrors.WithMessagef(err, "failed to set apiserver port to %d", controlConfig.HTTPSPort)
} }
} }
apiServerURL := proxy.APIServerURL() apiServerURL := proxy.APIServerURL()
...@@ -452,7 +453,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -452,7 +453,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
if controlConfig.FlannelBackend != config.FlannelBackendNone && len(envInfo.FlannelIface) > 0 { if controlConfig.FlannelBackend != config.FlannelBackendNone && len(envInfo.FlannelIface) > 0 {
flannelIface, err = net.InterfaceByName(envInfo.FlannelIface) flannelIface, err = net.InterfaceByName(envInfo.FlannelIface)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "unable to find interface %s", envInfo.FlannelIface) return nil, pkgerrors.WithMessagef(err, "unable to find interface %s", envInfo.FlannelIface)
} }
} }
...@@ -508,7 +509,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -508,7 +509,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
vpnIPs = append(vpnIPs, vpnInfo.IPv4Address) vpnIPs = append(vpnIPs, vpnInfo.IPv4Address)
} }
} else { } else {
return nil, errors.Errorf("address family mismatch when assigning VPN addresses to node: node=%v, VPN ipv4=%v ipv6=%v", nodeIPs, vpnInfo.IPv4Address, vpnInfo.IPv6Address) return nil, fmt.Errorf("address family mismatch when assigning VPN addresses to node: node=%v, VPN ipv4=%v ipv6=%v", nodeIPs, vpnInfo.IPv4Address, vpnInfo.IPv6Address)
} }
// Overwrite nodeip and flannel interface and throw a warning if user explicitly set those parameters // Overwrite nodeip and flannel interface and throw a warning if user explicitly set those parameters
...@@ -523,7 +524,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -523,7 +524,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
nodeIPs = vpnIPs nodeIPs = vpnIPs
flannelIface, err = net.InterfaceByName(vpnInfo.VPNInterface) flannelIface, err = net.InterfaceByName(vpnInfo.VPNInterface)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "unable to find vpn interface: %s", vpnInfo.VPNInterface) return nil, pkgerrors.WithMessagef(err, "unable to find vpn interface: %s", vpnInfo.VPNInterface)
} }
} }
} }
...@@ -558,12 +559,12 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -558,12 +559,12 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
// Ask the server to sign our kubelet server cert. // Ask the server to sign our kubelet server cert.
if err := getKubeletServingCert(nodeName, nodeExternalAndInternalIPs, servingKubeletCert, servingKubeletKey, newNodePasswordFile, info); err != nil { if err := getKubeletServingCert(nodeName, nodeExternalAndInternalIPs, servingKubeletCert, servingKubeletKey, newNodePasswordFile, info); err != nil {
return nil, errors.Wrap(err, servingKubeletCert) return nil, pkgerrors.WithMessage(err, servingKubeletCert)
} }
// Ask the server to sign our kubelet client cert. // Ask the server to sign our kubelet client cert.
if err := getKubeletClientCert(clientKubeletCert, clientKubeletKey, nodeName, nodeIPs, newNodePasswordFile, info); err != nil { if err := getKubeletClientCert(clientKubeletCert, clientKubeletKey, nodeName, nodeIPs, newNodePasswordFile, info); err != nil {
return nil, errors.Wrap(err, clientKubeletCert) return nil, pkgerrors.WithMessage(err, clientKubeletCert)
} }
// Generate a kubeconfig for the kubelet. // Generate a kubeconfig for the kubelet.
...@@ -577,7 +578,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -577,7 +578,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
// Ask the server to sign our kube-proxy client cert. // Ask the server to sign our kube-proxy client cert.
if err := getClientCert(clientKubeProxyCert, clientKubeProxyKey, info); err != nil { if err := getClientCert(clientKubeProxyCert, clientKubeProxyKey, info); err != nil {
return nil, errors.Wrap(err, clientKubeProxyCert) return nil, pkgerrors.WithMessage(err, clientKubeProxyCert)
} }
// Generate a kubeconfig for kube-proxy. // Generate a kubeconfig for kube-proxy.
...@@ -591,7 +592,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -591,7 +592,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
// Ask the server to sign our agent controller client cert. // Ask the server to sign our agent controller client cert.
if err := getClientCert(clientK3sControllerCert, clientK3sControllerKey, info); err != nil { if err := getClientCert(clientK3sControllerCert, clientK3sControllerKey, info); err != nil {
return nil, errors.Wrap(err, clientK3sControllerCert) return nil, pkgerrors.WithMessage(err, clientK3sControllerCert)
} }
// Generate a kubeconfig for the agent controller. // Generate a kubeconfig for the agent controller.
...@@ -653,7 +654,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -653,7 +654,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
} else { } else {
listenAddress, _, _, err := util.GetDefaultAddresses(nodeIPs[0]) listenAddress, _, _, err := util.GetDefaultAddresses(nodeIPs[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "cannot configure IPv4/IPv6 node-ip") return nil, pkgerrors.WithMessage(err, "cannot configure IPv4/IPv6 node-ip")
} }
nodeConfig.AgentConfig.ListenAddress = listenAddress nodeConfig.AgentConfig.ListenAddress = listenAddress
} }
...@@ -684,7 +685,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N ...@@ -684,7 +685,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
if !nodeConfig.NoFlannel { if !nodeConfig.NoFlannel {
hostLocal, err := exec.LookPath("host-local") hostLocal, err := exec.LookPath("host-local")
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to find host-local") return nil, pkgerrors.WithMessagef(err, "failed to find host-local")
} }
if envInfo.FlannelConf == "" { if envInfo.FlannelConf == "" {
...@@ -851,7 +852,7 @@ func getKubeProxyDisabled(ctx context.Context, node *config.Node, proxy proxy.Pr ...@@ -851,7 +852,7 @@ func getKubeProxyDisabled(ctx context.Context, node *config.Node, proxy proxy.Pr
controlConfig, err := getConfig(info) controlConfig, err := getConfig(info)
if err != nil { if err != nil {
return false, errors.Wrap(err, "failed to retrieve configuration from server") return false, pkgerrors.WithMessage(err, "failed to retrieve configuration from server")
} }
return controlConfig.DisableKubeProxy, nil return controlConfig.DisableKubeProxy, nil
......
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
package config package config
import ( import (
"errors"
"os" "os"
"path/filepath" "path/filepath"
"github.com/k3s-io/k3s/pkg/agent/containerd" "github.com/k3s-io/k3s/pkg/agent/containerd"
"github.com/k3s-io/k3s/pkg/cli/cmds" "github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -24,17 +25,17 @@ func applyContainerdOSSpecificConfig(nodeConfig *config.Node) error { ...@@ -24,17 +25,17 @@ func applyContainerdOSSpecificConfig(nodeConfig *config.Node) error {
switch nodeConfig.AgentConfig.Snapshotter { switch nodeConfig.AgentConfig.Snapshotter {
case "overlayfs": case "overlayfs":
if err := containerd.OverlaySupported(nodeConfig.Containerd.Root); err != nil { if err := containerd.OverlaySupported(nodeConfig.Containerd.Root); err != nil {
return errors.Wrapf(err, "\"overlayfs\" snapshotter cannot be enabled for %q, try using \"fuse-overlayfs\" or \"native\"", return pkgerrors.WithMessagef(err, "\"overlayfs\" snapshotter cannot be enabled for %q, try using \"fuse-overlayfs\" or \"native\"",
nodeConfig.Containerd.Root) nodeConfig.Containerd.Root)
} }
case "fuse-overlayfs": case "fuse-overlayfs":
if err := containerd.FuseoverlayfsSupported(nodeConfig.Containerd.Root); err != nil { if err := containerd.FuseoverlayfsSupported(nodeConfig.Containerd.Root); err != nil {
return errors.Wrapf(err, "\"fuse-overlayfs\" snapshotter cannot be enabled for %q, try using \"native\"", return pkgerrors.WithMessagef(err, "\"fuse-overlayfs\" snapshotter cannot be enabled for %q, try using \"native\"",
nodeConfig.Containerd.Root) nodeConfig.Containerd.Root)
} }
case "stargz": case "stargz":
if err := containerd.StargzSupported(nodeConfig.Containerd.Root); err != nil { if err := containerd.StargzSupported(nodeConfig.Containerd.Root); err != nil {
return errors.Wrapf(err, "\"stargz\" snapshotter cannot be enabled for %q, try using \"overlayfs\" or \"native\"", return pkgerrors.WithMessagef(err, "\"stargz\" snapshotter cannot be enabled for %q, try using \"overlayfs\" or \"native\"",
nodeConfig.Containerd.Root) nodeConfig.Containerd.Root)
} }
nodeConfig.AgentConfig.ImageServiceSocket = "/run/containerd-stargz-grpc/containerd-stargz-grpc.sock" nodeConfig.AgentConfig.ImageServiceSocket = "/run/containerd-stargz-grpc/containerd-stargz-grpc.sock"
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/k3s-io/k3s/pkg/cli/cmds" "github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/permissions/pkg/access" "github.com/rancher/permissions/pkg/access"
"github.com/rancher/permissions/pkg/acl" "github.com/rancher/permissions/pkg/acl"
"github.com/rancher/permissions/pkg/sid" "github.com/rancher/permissions/pkg/sid"
...@@ -46,7 +46,7 @@ func configureACL(file string) error { ...@@ -46,7 +46,7 @@ func configureACL(file string) error {
access.GrantSid(windows.GENERIC_ALL, sid.LocalSystem()), access.GrantSid(windows.GENERIC_ALL, sid.LocalSystem()),
access.GrantSid(windows.GENERIC_ALL, sid.BuiltinAdministrators()), access.GrantSid(windows.GENERIC_ALL, sid.BuiltinAdministrators()),
}...); err != nil { }...); err != nil {
return errors.Wrapf(err, "failed to configure Access Control List For %s", file) return pkgerrors.WithMessagef(err, "failed to configure Access Control List For %s", file)
} }
return nil return nil
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package containerd package containerd
import ( import (
"fmt"
"os" "os"
"github.com/containerd/containerd" "github.com/containerd/containerd"
...@@ -16,7 +17,7 @@ import ( ...@@ -16,7 +17,7 @@ import (
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/opencontainers/runc/libcontainer/userns" "github.com/opencontainers/runc/libcontainer/userns"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/kubelet/util" "k8s.io/kubernetes/pkg/kubelet/util"
...@@ -70,7 +71,7 @@ func SetupContainerdConfig(cfg *config.Node) error { ...@@ -70,7 +71,7 @@ func SetupContainerdConfig(cfg *config.Node) error {
// Verifies if the DefaultRuntime can be found // Verifies if the DefaultRuntime can be found
if _, ok := extraRuntimes[cfg.DefaultRuntime]; !ok && cfg.DefaultRuntime != "" { if _, ok := extraRuntimes[cfg.DefaultRuntime]; !ok && cfg.DefaultRuntime != "" {
return errors.Errorf("default runtime %s was not found", cfg.DefaultRuntime) return fmt.Errorf("default runtime %s was not found", cfg.DefaultRuntime)
} }
containerdConfig := templates.ContainerdConfig{ containerdConfig := templates.ContainerdConfig{
...@@ -88,7 +89,7 @@ func SetupContainerdConfig(cfg *config.Node) error { ...@@ -88,7 +89,7 @@ func SetupContainerdConfig(cfg *config.Node) error {
selEnabled, selConfigured, err := selinuxStatus() selEnabled, selConfigured, err := selinuxStatus()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to detect selinux") return pkgerrors.WithMessage(err, "failed to detect selinux")
} }
switch { switch {
case !cfg.SELinux && selEnabled: case !cfg.SELinux && selEnabled:
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/k3s-io/k3s/pkg/agent/templates" "github.com/k3s-io/k3s/pkg/agent/templates"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
util3 "github.com/k3s-io/k3s/pkg/util" util3 "github.com/k3s-io/k3s/pkg/util"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"k8s.io/kubernetes/pkg/kubelet/util" "k8s.io/kubernetes/pkg/kubelet/util"
) )
...@@ -64,13 +64,13 @@ func Client(address string) (*containerd.Client, error) { ...@@ -64,13 +64,13 @@ func Client(address string) (*containerd.Client, error) {
} }
func OverlaySupported(root string) error { func OverlaySupported(root string) error {
return errors.Wrapf(util3.ErrUnsupportedPlatform, "overlayfs is not supported") return pkgerrors.WithMessagef(util3.ErrUnsupportedPlatform, "overlayfs is not supported")
} }
func FuseoverlayfsSupported(root string) error { func FuseoverlayfsSupported(root string) error {
return errors.Wrapf(util3.ErrUnsupportedPlatform, "fuse-overlayfs is not supported") return pkgerrors.WithMessagef(util3.ErrUnsupportedPlatform, "fuse-overlayfs is not supported")
} }
func StargzSupported(root string) error { func StargzSupported(root string) error {
return errors.Wrapf(util3.ErrUnsupportedPlatform, "stargz is not supported") return pkgerrors.WithMessagef(util3.ErrUnsupportedPlatform, "stargz is not supported")
} }
...@@ -3,6 +3,7 @@ package containerd ...@@ -3,6 +3,7 @@ package containerd
import ( import (
"bufio" "bufio"
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -24,7 +25,7 @@ import ( ...@@ -24,7 +25,7 @@ import (
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/natefinch/lumberjack" "github.com/natefinch/lumberjack"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/wharfie/pkg/tarfile" "github.com/rancher/wharfie/pkg/tarfile"
"github.com/rancher/wrangler/pkg/merr" "github.com/rancher/wrangler/pkg/merr"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
...@@ -137,12 +138,12 @@ func PreloadImages(ctx context.Context, cfg *config.Node) error { ...@@ -137,12 +138,12 @@ func PreloadImages(ctx context.Context, cfg *config.Node) error {
// At startup all leases from k3s are cleared; we no longer use leases to lock content // At startup all leases from k3s are cleared; we no longer use leases to lock content
if err := clearLeases(ctx, client); err != nil { if err := clearLeases(ctx, client); err != nil {
return errors.Wrap(err, "failed to clear leases") return pkgerrors.WithMessage(err, "failed to clear leases")
} }
// Clear the pinned labels on all images previously pinned by k3s // Clear the pinned labels on all images previously pinned by k3s
if err := clearLabels(ctx, client); err != nil { if err := clearLabels(ctx, client); err != nil {
return errors.Wrap(err, "failed to clear pinned labels") return pkgerrors.WithMessage(err, "failed to clear pinned labels")
} }
go watchImages(ctx, cfg) go watchImages(ctx, cfg)
...@@ -199,7 +200,7 @@ func preloadFile(ctx context.Context, cfg *config.Node, client *containerd.Clien ...@@ -199,7 +200,7 @@ func preloadFile(ctx context.Context, cfg *config.Node, client *containerd.Clien
logrus.Infof("Pulling images from %s", filePath) logrus.Infof("Pulling images from %s", filePath)
images, err = prePullImages(ctx, client, imageClient, file) images, err = prePullImages(ctx, client, imageClient, file)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to pull images from "+filePath) return pkgerrors.WithMessage(err, "failed to pull images from "+filePath)
} }
} else { } else {
opener, err := tarfile.GetOpener(filePath) opener, err := tarfile.GetOpener(filePath)
...@@ -216,15 +217,15 @@ func preloadFile(ctx context.Context, cfg *config.Node, client *containerd.Clien ...@@ -216,15 +217,15 @@ func preloadFile(ctx context.Context, cfg *config.Node, client *containerd.Clien
logrus.Infof("Importing images from %s", filePath) logrus.Infof("Importing images from %s", filePath)
images, err = client.Import(ctx, imageReader, containerd.WithAllPlatforms(true), containerd.WithSkipMissing()) images, err = client.Import(ctx, imageReader, containerd.WithAllPlatforms(true), containerd.WithSkipMissing())
if err != nil { if err != nil {
return errors.Wrap(err, "failed to import images from "+filePath) return pkgerrors.WithMessage(err, "failed to import images from "+filePath)
} }
} }
if err := labelImages(ctx, client, images, filepath.Base(filePath)); err != nil { if err := labelImages(ctx, client, images, filepath.Base(filePath)); err != nil {
return errors.Wrap(err, "failed to add pinned label to images") return pkgerrors.WithMessage(err, "failed to add pinned label to images")
} }
if err := retagImages(ctx, client, images, cfg.AgentConfig.AirgapExtraRegistry); err != nil { if err := retagImages(ctx, client, images, cfg.AgentConfig.AirgapExtraRegistry); err != nil {
return errors.Wrap(err, "failed to retag images") return pkgerrors.WithMessage(err, "failed to retag images")
} }
for _, image := range images { for _, image := range images {
...@@ -263,7 +264,7 @@ func clearLabels(ctx context.Context, client *containerd.Client) error { ...@@ -263,7 +264,7 @@ func clearLabels(ctx context.Context, client *containerd.Client) error {
delete(image.Labels, k3sPinnedImageLabelKey) delete(image.Labels, k3sPinnedImageLabelKey)
delete(image.Labels, labels.PinnedImageLabelKey) delete(image.Labels, labels.PinnedImageLabelKey)
if _, err := imageService.Update(ctx, image, "labels"); err != nil { if _, err := imageService.Update(ctx, image, "labels"); err != nil {
errs = append(errs, errors.Wrap(err, "failed to delete labels from image "+image.Name)) errs = append(errs, pkgerrors.WithMessage(err, "failed to delete labels from image "+image.Name))
} }
} }
return merr.NewErrors(errs...) return merr.NewErrors(errs...)
...@@ -288,7 +289,7 @@ func labelImages(ctx context.Context, client *containerd.Client, images []images ...@@ -288,7 +289,7 @@ func labelImages(ctx context.Context, client *containerd.Client, images []images
image.Labels[labels.PinnedImageLabelKey] = labels.PinnedImageLabelValue image.Labels[labels.PinnedImageLabelKey] = labels.PinnedImageLabelValue
updatedImage, err := imageService.Update(ctx, image, "labels") updatedImage, err := imageService.Update(ctx, image, "labels")
if err != nil { if err != nil {
errs = append(errs, errors.Wrap(err, "failed to add labels to image "+image.Name)) errs = append(errs, pkgerrors.WithMessage(err, "failed to add labels to image "+image.Name))
} else { } else {
images[i] = updatedImage images[i] = updatedImage
} }
...@@ -305,7 +306,7 @@ func retagImages(ctx context.Context, client *containerd.Client, images []images ...@@ -305,7 +306,7 @@ func retagImages(ctx context.Context, client *containerd.Client, images []images
for _, image := range images { for _, image := range images {
name, err := parseNamedTagged(image.Name) name, err := parseNamedTagged(image.Name)
if err != nil { if err != nil {
errs = append(errs, errors.Wrap(err, "failed to parse tags for image "+image.Name)) errs = append(errs, pkgerrors.WithMessage(err, "failed to parse tags for image "+image.Name))
continue continue
} }
for _, registry := range registries { for _, registry := range registries {
...@@ -317,15 +318,15 @@ func retagImages(ctx context.Context, client *containerd.Client, images []images ...@@ -317,15 +318,15 @@ func retagImages(ctx context.Context, client *containerd.Client, images []images
if _, err = imageService.Create(ctx, image); err != nil { if _, err = imageService.Create(ctx, image); err != nil {
if errdefs.IsAlreadyExists(err) { if errdefs.IsAlreadyExists(err) {
if err = imageService.Delete(ctx, image.Name); err != nil { if err = imageService.Delete(ctx, image.Name); err != nil {
errs = append(errs, errors.Wrap(err, "failed to delete existing image "+image.Name)) errs = append(errs, pkgerrors.WithMessage(err, "failed to delete existing image "+image.Name))
continue continue
} }
if _, err = imageService.Create(ctx, image); err != nil { if _, err = imageService.Create(ctx, image); err != nil {
errs = append(errs, errors.Wrap(err, "failed to tag after deleting existing image "+image.Name)) errs = append(errs, pkgerrors.WithMessage(err, "failed to tag after deleting existing image "+image.Name))
continue continue
} }
} else { } else {
errs = append(errs, errors.Wrap(err, "failed to tag image "+image.Name)) errs = append(errs, pkgerrors.WithMessage(err, "failed to tag image "+image.Name))
continue continue
} }
} }
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/k3s-io/k3s/pkg/agent/cri" "github.com/k3s-io/k3s/pkg/agent/cri"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/wharfie/pkg/tarfile" "github.com/rancher/wharfie/pkg/tarfile"
"github.com/rancher/wrangler/pkg/merr" "github.com/rancher/wrangler/pkg/merr"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
...@@ -52,7 +52,7 @@ func isFileSupported(path string) bool { ...@@ -52,7 +52,7 @@ func isFileSupported(path string) bool {
func (w *Watcher) HandleWatch(path string) error { func (w *Watcher) HandleWatch(path string) error {
if err := w.watcher.Add(path); err != nil { if err := w.watcher.Add(path); err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to watch from %s directory: %v", path, err)) return pkgerrors.WithMessage(err, fmt.Sprintf("failed to watch from %s directory: %v", path, err))
} }
return nil return nil
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
) )
const socketPrefix = "unix://" const socketPrefix = "unix://"
...@@ -25,11 +25,11 @@ func setupDockerCRIConfig(ctx context.Context, cfg *config.Node) error { ...@@ -25,11 +25,11 @@ func setupDockerCRIConfig(ctx context.Context, cfg *config.Node) error {
} }
c, err := client.NewClientWithOpts(clientOpts...) c, err := client.NewClientWithOpts(clientOpts...)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create docker client") return pkgerrors.WithMessage(err, "failed to create docker client")
} }
i, err := c.Info(ctx) i, err := c.Info(ctx)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get docker runtime info") return pkgerrors.WithMessage(err, "failed to get docker runtime info")
} }
// note: this mutatation of the passed agent.Config is later used to set the // note: this mutatation of the passed agent.Config is later used to set the
// kubelet's cgroup-driver flag. This may merit moving to somewhere else in order // kubelet's cgroup-driver flag. This may merit moving to somewhere else in order
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
package flannel package flannel
import ( import (
"errors"
"fmt" "fmt"
"math/big" "math/big"
"net" "net"
...@@ -28,7 +29,7 @@ import ( ...@@ -28,7 +29,7 @@ import (
"github.com/flannel-io/flannel/pkg/subnet/kube" "github.com/flannel-io/flannel/pkg/subnet/kube"
"github.com/flannel-io/flannel/pkg/trafficmngr/iptables" "github.com/flannel-io/flannel/pkg/trafficmngr/iptables"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
...@@ -53,7 +54,7 @@ var ( ...@@ -53,7 +54,7 @@ var (
func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kubeConfigFile string, flannelIPv6Masq bool, netMode int) error { func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kubeConfigFile string, flannelIPv6Masq bool, netMode int) error {
extIface, err := LookupExtInterface(flannelIface, netMode) extIface, err := LookupExtInterface(flannelIface, netMode)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to find the interface") return pkgerrors.WithMessage(err, "failed to find the interface")
} }
sm, err := kube.NewSubnetManager(ctx, sm, err := kube.NewSubnetManager(ctx,
...@@ -63,12 +64,12 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube ...@@ -63,12 +64,12 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
flannelConf, flannelConf,
false) false)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create the SubnetManager") return pkgerrors.WithMessage(err, "failed to create the SubnetManager")
} }
config, err := sm.GetNetworkConfig(ctx) config, err := sm.GetNetworkConfig(ctx)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get the network config") return pkgerrors.WithMessage(err, "failed to get the network config")
} }
// Create a backend manager then use it to create the backend and register the network with it. // Create a backend manager then use it to create the backend and register the network with it.
...@@ -76,17 +77,17 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube ...@@ -76,17 +77,17 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
be, err := bm.GetBackend(config.BackendType) be, err := bm.GetBackend(config.BackendType)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create the flannel backend") return pkgerrors.WithMessage(err, "failed to create the flannel backend")
} }
bn, err := be.RegisterNetwork(ctx, &sync.WaitGroup{}, config) bn, err := be.RegisterNetwork(ctx, &sync.WaitGroup{}, config)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to register flannel network") return pkgerrors.WithMessage(err, "failed to register flannel network")
} }
trafficMngr := &iptables.IPTablesManager{} trafficMngr := &iptables.IPTablesManager{}
err = trafficMngr.Init(ctx, &sync.WaitGroup{}) err = trafficMngr.Init(ctx, &sync.WaitGroup{})
if err != nil { if err != nil {
return errors.Wrap(err, "failed to initialize flannel ipTables manager") return pkgerrors.WithMessage(err, "failed to initialize flannel ipTables manager")
} }
if netMode == (ipv4+ipv6) || netMode == ipv4 { if netMode == (ipv4+ipv6) || netMode == ipv4 {
...@@ -108,7 +109,7 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube ...@@ -108,7 +109,7 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
err = trafficMngr.SetupAndEnsureMasqRules(ctx, config.Network, prevSubnet, prevNetwork, ip.IP6Net{}, prevIPv6Subnet, prevIPv6Network, bn.Lease(), 60) err = trafficMngr.SetupAndEnsureMasqRules(ctx, config.Network, prevSubnet, prevNetwork, ip.IP6Net{}, prevIPv6Subnet, prevIPv6Network, bn.Lease(), 60)
} }
if err != nil { if err != nil {
return errors.Wrap(err, "failed to setup masq rules") return pkgerrors.WithMessage(err, "failed to setup masq rules")
} }
//setup forward rules //setup forward rules
...@@ -136,11 +137,11 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt ...@@ -136,11 +137,11 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
logrus.Debug("No interface defined for flannel in the config. Fetching the default gateway interface") logrus.Debug("No interface defined for flannel in the config. Fetching the default gateway interface")
if netMode == ipv4 || netMode == (ipv4+ipv6) { if netMode == ipv4 || netMode == (ipv4+ipv6) {
if iface, err = ip.GetDefaultGatewayInterface(); err != nil { if iface, err = ip.GetDefaultGatewayInterface(); err != nil {
return nil, errors.Wrap(err, "failed to get default interface") return nil, pkgerrors.WithMessage(err, "failed to get default interface")
} }
} else { } else {
if iface, err = ip.GetDefaultV6GatewayInterface(); err != nil { if iface, err = ip.GetDefaultV6GatewayInterface(); err != nil {
return nil, errors.Wrap(err, "failed to get default interface") return nil, pkgerrors.WithMessage(err, "failed to get default interface")
} }
} }
} }
...@@ -150,14 +151,14 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt ...@@ -150,14 +151,14 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
case ipv4: case ipv4:
ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface) ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to find IPv4 address for interface") return nil, pkgerrors.WithMessage(err, "failed to find IPv4 address for interface")
} }
logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0]) logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0])
ifacev6Addr = append(ifacev6Addr, nil) ifacev6Addr = append(ifacev6Addr, nil)
case ipv6: case ipv6:
ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface) ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to find IPv6 address for interface") return nil, pkgerrors.WithMessage(err, "failed to find IPv6 address for interface")
} }
logrus.Infof("The interface %s with ipv6 address %s will be used by flannel", iface.Name, ifacev6Addr[0]) logrus.Infof("The interface %s with ipv6 address %s will be used by flannel", iface.Name, ifacev6Addr[0])
ifaceAddr = append(ifaceAddr, nil) ifaceAddr = append(ifaceAddr, nil)
...@@ -264,7 +265,6 @@ func ReadCIDRsFromSubnetFile(path string, CIDRKey string) []ip.IP4Net { ...@@ -264,7 +265,6 @@ func ReadCIDRsFromSubnetFile(path string, CIDRKey string) []ip.IP4Net {
return prevCIDRs return prevCIDRs
} }
// ReadIP6CIDRFromSubnetFile reads the flannel subnet file and extracts the value of IPv6 network CIDRKey // ReadIP6CIDRFromSubnetFile reads the flannel subnet file and extracts the value of IPv6 network CIDRKey
func ReadIP6CIDRFromSubnetFile(path string, CIDRKey string) ip.IP6Net { func ReadIP6CIDRFromSubnetFile(path string, CIDRKey string) ip.IP6Net {
prevCIDRs := ReadIP6CIDRsFromSubnetFile(path, CIDRKey) prevCIDRs := ReadIP6CIDRsFromSubnetFile(path, CIDRKey)
......
...@@ -2,6 +2,7 @@ package flannel ...@@ -2,6 +2,7 @@ package flannel
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net" "net"
"os" "os"
...@@ -12,7 +13,7 @@ import ( ...@@ -12,7 +13,7 @@ import (
agentutil "github.com/k3s-io/k3s/pkg/agent/util" agentutil "github.com/k3s-io/k3s/pkg/agent/util"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
authorizationv1 "k8s.io/api/authorization/v1" authorizationv1 "k8s.io/api/authorization/v1"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
...@@ -75,11 +76,11 @@ func Run(ctx context.Context, nodeConfig *config.Node) error { ...@@ -75,11 +76,11 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
// Compatibility code for AuthorizeNodeWithSelectors feature-gate. // Compatibility code for AuthorizeNodeWithSelectors feature-gate.
// If the kubelet cannot list nodes, then wait for the k3s-controller RBAC to become ready, and use that kubeconfig instead. // If the kubelet cannot list nodes, then wait for the k3s-controller RBAC to become ready, and use that kubeconfig instead.
if canListNodes, err := util.CheckRBAC(ctx, kubeConfig, resourceAttrs, ""); err != nil { if canListNodes, err := util.CheckRBAC(ctx, kubeConfig, resourceAttrs, ""); err != nil {
return errors.Wrap(err, "failed to check if RBAC allows node list") return pkgerrors.WithMessage(err, "failed to check if RBAC allows node list")
} else if !canListNodes { } else if !canListNodes {
kubeConfig = nodeConfig.AgentConfig.KubeConfigK3sController kubeConfig = nodeConfig.AgentConfig.KubeConfigK3sController
if err := util.WaitForRBACReady(ctx, kubeConfig, util.DefaultAPIServerReadyTimeout, resourceAttrs, ""); err != nil { if err := util.WaitForRBACReady(ctx, kubeConfig, util.DefaultAPIServerReadyTimeout, resourceAttrs, ""); err != nil {
return errors.Wrap(err, "flannel failed to wait for RBAC") return pkgerrors.WithMessage(err, "flannel failed to wait for RBAC")
} }
} }
...@@ -89,12 +90,12 @@ func Run(ctx context.Context, nodeConfig *config.Node) error { ...@@ -89,12 +90,12 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
} }
if err := waitForPodCIDR(ctx, nodeConfig.AgentConfig.NodeName, coreClient.CoreV1().Nodes()); err != nil { if err := waitForPodCIDR(ctx, nodeConfig.AgentConfig.NodeName, coreClient.CoreV1().Nodes()); err != nil {
return errors.Wrap(err, "flannel failed to wait for PodCIDR assignment") return pkgerrors.WithMessage(err, "flannel failed to wait for PodCIDR assignment")
} }
netMode, err := findNetMode(nodeConfig.AgentConfig.ClusterCIDRs) netMode, err := findNetMode(nodeConfig.AgentConfig.ClusterCIDRs)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to check netMode for flannel") return pkgerrors.WithMessage(err, "failed to check netMode for flannel")
} }
go func() { go func() {
err := flannel(ctx, nodeConfig.FlannelIface, nodeConfig.FlannelConfFile, kubeConfig, nodeConfig.FlannelIPv6Masq, netMode) err := flannel(ctx, nodeConfig.FlannelIface, nodeConfig.FlannelConfFile, kubeConfig, nodeConfig.FlannelIPv6Masq, netMode)
...@@ -129,7 +130,7 @@ func waitForPodCIDR(ctx context.Context, nodeName string, nodes typedcorev1.Node ...@@ -129,7 +130,7 @@ func waitForPodCIDR(ctx context.Context, nodeName string, nodes typedcorev1.Node
} }
if _, err := toolswatch.UntilWithSync(ctx, lw, &v1.Node{}, nil, condition); err != nil { if _, err := toolswatch.UntilWithSync(ctx, lw, &v1.Node{}, nil, condition); err != nil {
return errors.Wrap(err, "failed to wait for PodCIDR assignment") return pkgerrors.WithMessage(err, "failed to wait for PodCIDR assignment")
} }
logrus.Info("Flannel found PodCIDR assigned for node " + nodeName) logrus.Info("Flannel found PodCIDR assigned for node " + nodeName)
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/generated/clientset/versioned/scheme" "github.com/k3s-io/api/pkg/generated/clientset/versioned/scheme"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/authentication/authenticator"
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
http_dialer "github.com/mwitkow/go-http-dialer" http_dialer "github.com/mwitkow/go-http-dialer"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/net/http/httpproxy" "golang.org/x/net/http/httpproxy"
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
...@@ -32,14 +32,14 @@ func SetHTTPProxy(address string) error { ...@@ -32,14 +32,14 @@ func SetHTTPProxy(address string) error {
serverURL, err := url.Parse(address) serverURL, err := url.Parse(address)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to parse address %s", address) return pkgerrors.WithMessagef(err, "failed to parse address %s", address)
} }
// Call this directly instead of using the cached environment used by http.ProxyFromEnvironment to allow for testing // Call this directly instead of using the cached environment used by http.ProxyFromEnvironment to allow for testing
proxyFromEnvironment := httpproxy.FromEnvironment().ProxyFunc() proxyFromEnvironment := httpproxy.FromEnvironment().ProxyFunc()
proxyURL, err := proxyFromEnvironment(serverURL) proxyURL, err := proxyFromEnvironment(serverURL)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to get proxy for address %s", address) return pkgerrors.WithMessagef(err, "failed to get proxy for address %s", address)
} }
if proxyURL == nil { if proxyURL == nil {
logrus.Debug(version.ProgramUpper + "_AGENT_HTTP_PROXY_ALLOWED is true but no proxy is configured for URL " + serverURL.String()) logrus.Debug(version.ProgramUpper + "_AGENT_HTTP_PROXY_ALLOWED is true but no proxy is configured for URL " + serverURL.String())
...@@ -48,7 +48,7 @@ func SetHTTPProxy(address string) error { ...@@ -48,7 +48,7 @@ func SetHTTPProxy(address string) error {
dialer, err := proxyDialer(proxyURL, defaultDialer) dialer, err := proxyDialer(proxyURL, defaultDialer)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create proxy dialer for %s", proxyURL) return pkgerrors.WithMessagef(err, "failed to create proxy dialer for %s", proxyURL)
} }
defaultDialer = dialer defaultDialer = dialer
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"time" "time"
"github.com/inetaf/tcpproxy" "github.com/inetaf/tcpproxy"
"github.com/k3s-io/k3s/pkg/util/metrics"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -99,13 +100,8 @@ func New(ctx context.Context, dataDir, serviceName, defaultServerURL string, lbS ...@@ -99,13 +100,8 @@ func New(ctx context.Context, dataDir, serviceName, defaultServerURL string, lbS
OnDialError: onDialError, OnDialError: onDialError,
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
start := time.Now() start := time.Now()
status := "success"
conn, err := lb.servers.dialContext(ctx, network, address) conn, err := lb.servers.dialContext(ctx, network, address)
latency := time.Since(start) metrics.ObserveWithStatus(loadbalancerDials, start, err, serviceName)
if err != nil {
status = "error"
}
loadbalancerDials.WithLabelValues(serviceName, status).Observe(latency.Seconds())
return conn, err return conn, err
}, },
}) })
......
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/metrics" "github.com/k3s-io/k3s/pkg/metrics"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
v1core "k8s.io/api/core/v1" v1core "k8s.io/api/core/v1"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
...@@ -86,7 +86,7 @@ func Run(ctx context.Context, nodeConfig *config.Node) error { ...@@ -86,7 +86,7 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
} }
return true, nil return true, nil
}); err != nil { }); err != nil {
return errors.Wrapf(err, "network policy controller failed to wait for %s taint to be removed from Node %s", cloudproviderapi.TaintExternalCloudProvider, nodeConfig.AgentConfig.NodeName) return pkgerrors.WithMessagef(err, "network policy controller failed to wait for %s taint to be removed from Node %s", cloudproviderapi.TaintExternalCloudProvider, nodeConfig.AgentConfig.NodeName)
} }
krConfig := options.NewKubeRouterConfig() krConfig := options.NewKubeRouterConfig()
...@@ -123,13 +123,13 @@ func Run(ctx context.Context, nodeConfig *config.Node) error { ...@@ -123,13 +123,13 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
if nodeConfig.AgentConfig.EnableIPv4 { if nodeConfig.AgentConfig.EnableIPv4 {
iptHandler, err := iptables.NewWithProtocol(iptables.ProtocolIPv4) iptHandler, err := iptables.NewWithProtocol(iptables.ProtocolIPv4)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create iptables handler") return pkgerrors.WithMessage(err, "failed to create iptables handler")
} }
iptablesCmdHandlers[v1core.IPv4Protocol] = iptHandler iptablesCmdHandlers[v1core.IPv4Protocol] = iptHandler
ipset, err := utils.NewIPSet(false) ipset, err := utils.NewIPSet(false)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create ipset handler") return pkgerrors.WithMessage(err, "failed to create ipset handler")
} }
ipSetHandlers[v1core.IPv4Protocol] = ipset ipSetHandlers[v1core.IPv4Protocol] = ipset
} }
...@@ -137,13 +137,13 @@ func Run(ctx context.Context, nodeConfig *config.Node) error { ...@@ -137,13 +137,13 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
if nodeConfig.AgentConfig.EnableIPv6 { if nodeConfig.AgentConfig.EnableIPv6 {
ipt6Handler, err := iptables.NewWithProtocol(iptables.ProtocolIPv6) ipt6Handler, err := iptables.NewWithProtocol(iptables.ProtocolIPv6)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create iptables handler") return pkgerrors.WithMessage(err, "failed to create iptables handler")
} }
iptablesCmdHandlers[v1core.IPv6Protocol] = ipt6Handler iptablesCmdHandlers[v1core.IPv6Protocol] = ipt6Handler
ipset, err := utils.NewIPSet(true) ipset, err := utils.NewIPSet(true)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create ipset handler") return pkgerrors.WithMessage(err, "failed to create ipset handler")
} }
ipSetHandlers[v1core.IPv6Protocol] = ipset ipSetHandlers[v1core.IPv6Protocol] = ipset
} }
...@@ -172,7 +172,7 @@ func Run(ctx context.Context, nodeConfig *config.Node) error { ...@@ -172,7 +172,7 @@ func Run(ctx context.Context, nodeConfig *config.Node) error {
npc, err := netpol.NewNetworkPolicyController(client, krConfig, podInformer, npInformer, nsInformer, &sync.Mutex{}, npc, err := netpol.NewNetworkPolicyController(client, krConfig, podInformer, npInformer, nsInformer, &sync.Mutex{},
iptablesCmdHandlers, ipSetHandlers) iptablesCmdHandlers, ipSetHandlers)
if err != nil { if err != nil {
return errors.Wrap(err, "unable to initialize network policy controller") return pkgerrors.WithMessage(err, "unable to initialize network policy controller")
} }
podInformer.AddEventHandler(npc.PodEventHandler) podInformer.AddEventHandler(npc.PodEventHandler)
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/k3s-io/k3s/pkg/agent/loadbalancer" "github.com/k3s-io/k3s/pkg/agent/loadbalancer"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
) )
type Proxy interface { type Proxy interface {
...@@ -58,7 +58,7 @@ func NewSupervisorProxy(ctx context.Context, lbEnabled bool, dataDir, supervisor ...@@ -58,7 +58,7 @@ func NewSupervisorProxy(ctx context.Context, lbEnabled bool, dataDir, supervisor
u, err := url.Parse(p.initialSupervisorURL) u, err := url.Parse(p.initialSupervisorURL)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to parse %s", p.initialSupervisorURL) return nil, pkgerrors.WithMessagef(err, "failed to parse %s", p.initialSupervisorURL)
} }
p.fallbackSupervisorAddress = u.Host p.fallbackSupervisorAddress = u.Host
p.supervisorPort = u.Port() p.supervisorPort = u.Port()
...@@ -140,7 +140,7 @@ func (p *proxy) SetAPIServerPort(port int, isIPv6 bool) error { ...@@ -140,7 +140,7 @@ func (p *proxy) SetAPIServerPort(port int, isIPv6 bool) error {
u, err := url.Parse(p.initialSupervisorURL) u, err := url.Parse(p.initialSupervisorURL)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to parse server URL %s", p.initialSupervisorURL) return pkgerrors.WithMessagef(err, "failed to parse server URL %s", p.initialSupervisorURL)
} }
p.apiServerPort = strconv.Itoa(port) p.apiServerPort = strconv.Itoa(port)
u.Host = sysnet.JoinHostPort(u.Hostname(), p.apiServerPort) u.Host = sysnet.JoinHostPort(u.Hostname(), p.apiServerPort)
......
...@@ -2,6 +2,7 @@ package agent ...@@ -2,6 +2,7 @@ package agent
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net" "net"
"os" "os"
...@@ -34,7 +35,7 @@ import ( ...@@ -34,7 +35,7 @@ import (
"github.com/k3s-io/k3s/pkg/spegel" "github.com/k3s-io/k3s/pkg/spegel"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/equality"
...@@ -57,20 +58,20 @@ import ( ...@@ -57,20 +58,20 @@ import (
func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error { func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
nodeConfig, err := config.Get(ctx, cfg, proxy) nodeConfig, err := config.Get(ctx, cfg, proxy)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to retrieve agent configuration") return pkgerrors.WithMessage(err, "failed to retrieve agent configuration")
} }
dualCluster, err := utilsnet.IsDualStackCIDRs(nodeConfig.AgentConfig.ClusterCIDRs) dualCluster, err := utilsnet.IsDualStackCIDRs(nodeConfig.AgentConfig.ClusterCIDRs)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to validate cluster-cidr") return pkgerrors.WithMessage(err, "failed to validate cluster-cidr")
} }
dualService, err := utilsnet.IsDualStackCIDRs(nodeConfig.AgentConfig.ServiceCIDRs) dualService, err := utilsnet.IsDualStackCIDRs(nodeConfig.AgentConfig.ServiceCIDRs)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to validate service-cidr") return pkgerrors.WithMessage(err, "failed to validate service-cidr")
} }
dualNode, err := utilsnet.IsDualStackIPs(nodeConfig.AgentConfig.NodeIPs) dualNode, err := utilsnet.IsDualStackIPs(nodeConfig.AgentConfig.NodeIPs)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to validate node-ip") return pkgerrors.WithMessage(err, "failed to validate node-ip")
} }
serviceIPv4 := utilsnet.IsIPv4CIDR(nodeConfig.AgentConfig.ServiceCIDR) serviceIPv4 := utilsnet.IsIPv4CIDR(nodeConfig.AgentConfig.ServiceCIDR)
clusterIPv4 := utilsnet.IsIPv4CIDR(nodeConfig.AgentConfig.ClusterCIDR) clusterIPv4 := utilsnet.IsIPv4CIDR(nodeConfig.AgentConfig.ClusterCIDR)
...@@ -99,7 +100,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error { ...@@ -99,7 +100,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
conntrackConfig, err := getConntrackConfig(nodeConfig) conntrackConfig, err := getConntrackConfig(nodeConfig)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to validate kube-proxy conntrack configuration") return pkgerrors.WithMessage(err, "failed to validate kube-proxy conntrack configuration")
} }
syssetup.Configure(enableIPv6, conntrackConfig) syssetup.Configure(enableIPv6, conntrackConfig)
nodeConfig.AgentConfig.EnableIPv4 = enableIPv4 nodeConfig.AgentConfig.EnableIPv4 = enableIPv4
...@@ -111,19 +112,19 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error { ...@@ -111,19 +112,19 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
} }
if err := spegel.DefaultRegistry.Start(ctx, nodeConfig); err != nil { if err := spegel.DefaultRegistry.Start(ctx, nodeConfig); err != nil {
return errors.Wrap(err, "failed to start embedded registry") return pkgerrors.WithMessage(err, "failed to start embedded registry")
} }
} }
if nodeConfig.SupervisorMetrics { if nodeConfig.SupervisorMetrics {
if err := metrics.DefaultMetrics.Start(ctx, nodeConfig); err != nil { if err := metrics.DefaultMetrics.Start(ctx, nodeConfig); err != nil {
return errors.Wrap(err, "failed to serve metrics") return pkgerrors.WithMessage(err, "failed to serve metrics")
} }
} }
if nodeConfig.EnablePProf { if nodeConfig.EnablePProf {
if err := profile.DefaultProfiler.Start(ctx, nodeConfig); err != nil { if err := profile.DefaultProfiler.Start(ctx, nodeConfig); err != nil {
return errors.Wrap(err, "failed to serve pprof") return pkgerrors.WithMessage(err, "failed to serve pprof")
} }
} }
...@@ -174,7 +175,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error { ...@@ -174,7 +175,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
} }
if err := util.WaitForAPIServerReady(ctx, nodeConfig.AgentConfig.KubeConfigKubelet, util.DefaultAPIServerReadyTimeout); err != nil { if err := util.WaitForAPIServerReady(ctx, nodeConfig.AgentConfig.KubeConfigKubelet, util.DefaultAPIServerReadyTimeout); err != nil {
return errors.Wrap(err, "failed to wait for apiserver ready") return pkgerrors.WithMessage(err, "failed to wait for apiserver ready")
} }
// Use the kubelet kubeconfig to update annotations on the local node // Use the kubelet kubeconfig to update annotations on the local node
...@@ -267,7 +268,7 @@ func RunStandalone(ctx context.Context, cfg cmds.Agent) error { ...@@ -267,7 +268,7 @@ func RunStandalone(ctx context.Context, cfg cmds.Agent) error {
nodeConfig, err := config.Get(ctx, cfg, proxy) nodeConfig, err := config.Get(ctx, cfg, proxy)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to retrieve agent configuration") return pkgerrors.WithMessage(err, "failed to retrieve agent configuration")
} }
if err := executor.Bootstrap(ctx, nodeConfig, cfg); err != nil { if err := executor.Bootstrap(ctx, nodeConfig, cfg); err != nil {
...@@ -287,13 +288,13 @@ func RunStandalone(ctx context.Context, cfg cmds.Agent) error { ...@@ -287,13 +288,13 @@ func RunStandalone(ctx context.Context, cfg cmds.Agent) error {
if nodeConfig.SupervisorMetrics { if nodeConfig.SupervisorMetrics {
if err := metrics.DefaultMetrics.Start(ctx, nodeConfig); err != nil { if err := metrics.DefaultMetrics.Start(ctx, nodeConfig); err != nil {
return errors.Wrap(err, "failed to serve metrics") return pkgerrors.WithMessage(err, "failed to serve metrics")
} }
} }
if nodeConfig.EnablePProf { if nodeConfig.EnablePProf {
if err := profile.DefaultProfiler.Start(ctx, nodeConfig); err != nil { if err := profile.DefaultProfiler.Start(ctx, nodeConfig); err != nil {
return errors.Wrap(err, "failed to serve pprof") return pkgerrors.WithMessage(err, "failed to serve pprof")
} }
} }
...@@ -429,7 +430,7 @@ func configureNode(ctx context.Context, nodeConfig *daemonconfig.Node, nodes typ ...@@ -429,7 +430,7 @@ func configureNode(ctx context.Context, nodeConfig *daemonconfig.Node, nodes typ
} }
if _, err := toolswatch.UntilWithSync(ctx, lw, &v1.Node{}, nil, condition); err != nil { if _, err := toolswatch.UntilWithSync(ctx, lw, &v1.Node{}, nil, condition); err != nil {
return errors.Wrap(err, "failed to configure node") return pkgerrors.WithMessage(err, "failed to configure node")
} }
return nil return nil
} }
......
package util package util
import ( import (
"errors"
"os" "os"
"path/filepath" "path/filepath"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
) )
func WriteFile(name string, content string) error { func WriteFile(name string, content string) error {
os.MkdirAll(filepath.Dir(name), 0755) os.MkdirAll(filepath.Dir(name), 0755)
err := os.WriteFile(name, []byte(content), 0644) err := os.WriteFile(name, []byte(content), 0644)
if err != nil { if err != nil {
return errors.Wrapf(err, "writing %s", name) return pkgerrors.WithMessagef(err, "writing %s", name)
} }
return nil return nil
} }
...@@ -22,11 +23,11 @@ func CopyFile(sourceFile string, destinationFile string, ignoreNotExist bool) er ...@@ -22,11 +23,11 @@ func CopyFile(sourceFile string, destinationFile string, ignoreNotExist bool) er
if errors.Is(err, os.ErrNotExist) && ignoreNotExist { if errors.Is(err, os.ErrNotExist) && ignoreNotExist {
return nil return nil
} else if err != nil { } else if err != nil {
return errors.Wrapf(err, "copying %s to %s", sourceFile, destinationFile) return pkgerrors.WithMessagef(err, "copying %s to %s", sourceFile, destinationFile)
} }
err = os.WriteFile(destinationFile, input, 0644) err = os.WriteFile(destinationFile, input, 0644)
if err != nil { if err != nil {
return errors.Wrapf(err, "copying %s to %s", sourceFile, destinationFile) return pkgerrors.WithMessagef(err, "copying %s to %s", sourceFile, destinationFile)
} }
return nil return nil
} }
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
// +k8s:deepcopy-gen=package
// +groupName=k3s.cattle.io
package v1
package v1
import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Addon is used to track application of a manifest file on disk. It mostly exists so that the wrangler DesiredSet
// Apply controller has an object to track as the owner, and ensure that all created resources are tracked when the
// manifest is modified or removed.
type Addon struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec provides information about the on-disk manifest backing this resource.
Spec AddonSpec `json:"spec,omitempty"`
}
type AddonSpec struct {
// Source is the Path on disk to the manifest file that this Addon tracks.
Source string `json:"source,omitempty" column:""`
// Checksum is the SHA256 checksum of the most recently successfully applied manifest file.
Checksum string `json:"checksum,omitempty" column:""`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ETCDSnapshot tracks a point-in-time snapshot of the etcd datastore.
type ETCDSnapshotFile struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec defines properties of an etcd snapshot file
Spec ETCDSnapshotSpec `json:"spec,omitempty"`
// Status represents current information about a snapshot.
Status ETCDSnapshotStatus `json:"status,omitempty"`
}
// ETCDSnapshotSpec desribes an etcd snapshot file
type ETCDSnapshotSpec struct {
// SnapshotName contains the base name of the snapshot file. CLI actions that act
// on snapshots stored locally or within a pre-configured S3 bucket and
// prefix usually take the snapshot name as their argument.
SnapshotName string `json:"snapshotName" column:""`
// NodeName contains the name of the node that took the snapshot.
NodeName string `json:"nodeName" column:"name=Node"`
// Location is the absolute file:// or s3:// URI address of the snapshot.
Location string `json:"location" column:""`
// Metadata contains point-in-time snapshot of the contents of the
// k3s-etcd-snapshot-extra-metadata ConfigMap's data field, at the time the
// snapshot was taken. This is intended to contain data about cluster state
// that may be important for an external system to have available when restoring
// the snapshot.
Metadata map[string]string `json:"metadata,omitempty"`
// S3 contains extra metadata about the S3 storage system holding the
// snapshot. This is guaranteed to be set for all snapshots uploaded to S3.
// If not specified, the snapshot was not uploaded to S3.
S3 *ETCDSnapshotS3 `json:"s3,omitempty"`
}
// ETCDSnapshotS3 holds information about the S3 storage system holding the snapshot.
type ETCDSnapshotS3 struct {
// Endpoint is the host or host:port of the S3 service
Endpoint string `json:"endpoint,omitempty"`
// EndpointCA is the path on disk to the S3 service's trusted CA list. Leave empty to use the OS CA bundle.
EndpointCA string `json:"endpointCA,omitempty"`
// SkipSSLVerify is true if TLS certificate verification is disabled
SkipSSLVerify bool `json:"skipSSLVerify,omitempty"`
// Bucket is the bucket holding the snapshot
Bucket string `json:"bucket,omitempty"`
// Region is the region of the S3 service
Region string `json:"region,omitempty"`
// Prefix is the prefix in which the snapshot file is stored.
Prefix string `json:"prefix,omitempty"`
// Insecure is true if the S3 service uses HTTP instead of HTTPS
Insecure bool `json:"insecure,omitempty"`
}
// ETCDSnapshotStatus is the status of the ETCDSnapshotFile object.
type ETCDSnapshotStatus struct {
// Size is the size of the snapshot file, in bytes. If not specified, the snapshot failed.
Size *resource.Quantity `json:"size,omitempty" column:""`
// CreationTime is the timestamp when the snapshot was taken by etcd.
CreationTime *metav1.Time `json:"creationTime,omitempty" column:""`
// ReadyToUse indicates that the snapshot is available to be restored.
ReadyToUse *bool `json:"readyToUse,omitempty"`
// Error is the last observed error during snapshot creation, if any.
// If the snapshot is retried, this field will be cleared on success.
Error *ETCDSnapshotError `json:"error,omitempty"`
}
// ETCDSnapshotError describes an error encountered during snapshot creation.
type ETCDSnapshotError struct {
// Time is the timestamp when the error was encountered.
Time *metav1.Time `json:"time,omitempty"`
// Message is a string detailing the encountered error during snapshot creation if specified.
// NOTE: message may be logged, and it should not contain sensitive information.
Message *string `json:"message,omitempty"`
}
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Addon) DeepCopyInto(out *Addon) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Addon.
func (in *Addon) DeepCopy() *Addon {
if in == nil {
return nil
}
out := new(Addon)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Addon) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AddonList) DeepCopyInto(out *AddonList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Addon, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddonList.
func (in *AddonList) DeepCopy() *AddonList {
if in == nil {
return nil
}
out := new(AddonList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *AddonList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AddonSpec) DeepCopyInto(out *AddonSpec) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddonSpec.
func (in *AddonSpec) DeepCopy() *AddonSpec {
if in == nil {
return nil
}
out := new(AddonSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ETCDSnapshotError) DeepCopyInto(out *ETCDSnapshotError) {
*out = *in
if in.Time != nil {
in, out := &in.Time, &out.Time
*out = (*in).DeepCopy()
}
if in.Message != nil {
in, out := &in.Message, &out.Message
*out = new(string)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ETCDSnapshotError.
func (in *ETCDSnapshotError) DeepCopy() *ETCDSnapshotError {
if in == nil {
return nil
}
out := new(ETCDSnapshotError)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ETCDSnapshotFile) DeepCopyInto(out *ETCDSnapshotFile) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
in.Status.DeepCopyInto(&out.Status)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ETCDSnapshotFile.
func (in *ETCDSnapshotFile) DeepCopy() *ETCDSnapshotFile {
if in == nil {
return nil
}
out := new(ETCDSnapshotFile)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ETCDSnapshotFile) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ETCDSnapshotFileList) DeepCopyInto(out *ETCDSnapshotFileList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]ETCDSnapshotFile, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ETCDSnapshotFileList.
func (in *ETCDSnapshotFileList) DeepCopy() *ETCDSnapshotFileList {
if in == nil {
return nil
}
out := new(ETCDSnapshotFileList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ETCDSnapshotFileList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ETCDSnapshotS3) DeepCopyInto(out *ETCDSnapshotS3) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ETCDSnapshotS3.
func (in *ETCDSnapshotS3) DeepCopy() *ETCDSnapshotS3 {
if in == nil {
return nil
}
out := new(ETCDSnapshotS3)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ETCDSnapshotSpec) DeepCopyInto(out *ETCDSnapshotSpec) {
*out = *in
if in.Metadata != nil {
in, out := &in.Metadata, &out.Metadata
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.S3 != nil {
in, out := &in.S3, &out.S3
*out = new(ETCDSnapshotS3)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ETCDSnapshotSpec.
func (in *ETCDSnapshotSpec) DeepCopy() *ETCDSnapshotSpec {
if in == nil {
return nil
}
out := new(ETCDSnapshotSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ETCDSnapshotStatus) DeepCopyInto(out *ETCDSnapshotStatus) {
*out = *in
if in.Size != nil {
in, out := &in.Size, &out.Size
x := (*in).DeepCopy()
*out = &x
}
if in.CreationTime != nil {
in, out := &in.CreationTime, &out.CreationTime
*out = (*in).DeepCopy()
}
if in.ReadyToUse != nil {
in, out := &in.ReadyToUse, &out.ReadyToUse
*out = new(bool)
**out = **in
}
if in.Error != nil {
in, out := &in.Error, &out.Error
*out = new(ETCDSnapshotError)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ETCDSnapshotStatus.
func (in *ETCDSnapshotStatus) DeepCopy() *ETCDSnapshotStatus {
if in == nil {
return nil
}
out := new(ETCDSnapshotStatus)
in.DeepCopyInto(out)
return out
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
// +k8s:deepcopy-gen=package
// +groupName=k3s.cattle.io
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// AddonList is a list of Addon resources
type AddonList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Addon `json:"items"`
}
func NewAddon(namespace, name string, obj Addon) *Addon {
obj.APIVersion, obj.Kind = SchemeGroupVersion.WithKind("Addon").ToAPIVersionAndKind()
obj.Name = name
obj.Namespace = namespace
return &obj
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ETCDSnapshotFileList is a list of ETCDSnapshotFile resources
type ETCDSnapshotFileList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []ETCDSnapshotFile `json:"items"`
}
func NewETCDSnapshotFile(namespace, name string, obj ETCDSnapshotFile) *ETCDSnapshotFile {
obj.APIVersion, obj.Kind = SchemeGroupVersion.WithKind("ETCDSnapshotFile").ToAPIVersionAndKind()
obj.Name = name
obj.Namespace = namespace
return &obj
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
// +k8s:deepcopy-gen=package
// +groupName=k3s.cattle.io
package v1
import (
k3s "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var (
AddonResourceName = "addons"
ETCDSnapshotFileResourceName = "etcdsnapshotfiles"
)
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: k3s.GroupName, Version: "v1"}
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
)
// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Addon{},
&AddonList{},
&ETCDSnapshotFile{},
&ETCDSnapshotFileList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package k3s
const (
// Package-wide consts from generator "zz_generated_register".
GroupName = "k3s.cattle.io"
)
...@@ -3,23 +3,15 @@ package bootstrap ...@@ -3,23 +3,15 @@ package bootstrap
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"net/http"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
func Handler(bootstrap *config.ControlRuntimeBootstrap) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Content-Type", "application/json")
ReadFromDisk(rw, bootstrap)
})
}
// ReadFromDisk reads the bootstrap data from the files on disk and // ReadFromDisk reads the bootstrap data from the files on disk and
// writes their content in JSON form to the given io.Writer. // writes their content in JSON form to the given io.Writer.
func ReadFromDisk(w io.Writer, bootstrap *config.ControlRuntimeBootstrap) error { func ReadFromDisk(w io.Writer, bootstrap *config.ControlRuntimeBootstrap) error {
...@@ -79,13 +71,13 @@ func WriteToDiskFromStorage(files PathsDataformat, bootstrap *config.ControlRunt ...@@ -79,13 +71,13 @@ func WriteToDiskFromStorage(files PathsDataformat, bootstrap *config.ControlRunt
} }
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil { if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
return errors.Wrapf(err, "failed to mkdir %s", filepath.Dir(path)) return pkgerrors.WithMessagef(err, "failed to mkdir %s", filepath.Dir(path))
} }
if err := os.WriteFile(path, bsf.Content, 0600); err != nil { if err := os.WriteFile(path, bsf.Content, 0600); err != nil {
return errors.Wrapf(err, "failed to write to %s", path) return pkgerrors.WithMessagef(err, "failed to write to %s", path)
} }
if err := os.Chtimes(path, bsf.Timestamp, bsf.Timestamp); err != nil { if err := os.Chtimes(path, bsf.Timestamp, bsf.Timestamp); err != nil {
return errors.Wrapf(err, "failed to update modified time on %s", path) return pkgerrors.WithMessagef(err, "failed to update modified time on %s", path)
} }
} }
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
"github.com/k3s-io/k3s/pkg/util/permissions" "github.com/k3s-io/k3s/pkg/util/permissions"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/k3s-io/k3s/pkg/vpn" "github.com/k3s-io/k3s/pkg/vpn"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/wrangler/pkg/signals" "github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
...@@ -48,7 +48,7 @@ func Run(ctx *cli.Context) error { ...@@ -48,7 +48,7 @@ func Run(ctx *cli.Context) error {
if !cmds.AgentConfig.Rootless { if !cmds.AgentConfig.Rootless {
if err := permissions.IsPrivileged(); err != nil { if err := permissions.IsPrivileged(); err != nil {
return errors.Wrap(err, "agent requires additional privilege if not run with --rootless") return pkgerrors.WithMessage(err, "agent requires additional privilege if not run with --rootless")
} }
} }
......
...@@ -2,6 +2,7 @@ package cert ...@@ -2,6 +2,7 @@ package cert
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
...@@ -21,7 +22,7 @@ import ( ...@@ -21,7 +22,7 @@ import (
"github.com/k3s-io/k3s/pkg/util/services" "github.com/k3s-io/k3s/pkg/util/services"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/otiai10/copy" "github.com/otiai10/copy"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
certutil "github.com/rancher/dynamiclistener/cert" certutil "github.com/rancher/dynamiclistener/cert"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
...@@ -302,7 +303,7 @@ func rotateCA(app *cli.Context, cfg *cmds.Server, sync *cmds.CertRotateCA) error ...@@ -302,7 +303,7 @@ func rotateCA(app *cli.Context, cfg *cmds.Server, sync *cmds.CertRotateCA) error
url := fmt.Sprintf("/v1-%s/cert/cacerts?force=%t", version.Program, sync.Force) url := fmt.Sprintf("/v1-%s/cert/cacerts?force=%t", version.Program, sync.Force)
if err = info.Put(url, buf.Bytes()); err != nil { if err = info.Put(url, buf.Bytes()); err != nil {
return errors.Wrap(err, "see server log for details") return pkgerrors.WithMessage(err, "see server log for details")
} }
fmt.Println("certificates saved to datastore") fmt.Println("certificates saved to datastore")
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"os" "os"
"github.com/containerd/containerd/pkg/userns" "github.com/containerd/containerd/pkg/userns"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rootless-containers/rootlesskit/pkg/parent/cgrouputil" "github.com/rootless-containers/rootlesskit/pkg/parent/cgrouputil"
) )
...@@ -17,7 +17,7 @@ func EvacuateCgroup2() error { ...@@ -17,7 +17,7 @@ func EvacuateCgroup2() error {
// The root cgroup has to be empty to enable subtree_control, so evacuate it by placing // The root cgroup has to be empty to enable subtree_control, so evacuate it by placing
// ourselves in the init cgroup. // ourselves in the init cgroup.
if err := cgrouputil.EvacuateCgroup2("init"); err != nil { if err := cgrouputil.EvacuateCgroup2("init"); err != nil {
return errors.Wrap(err, "failed to evacuate root cgroup") return pkgerrors.WithMessage(err, "failed to evacuate root cgroup")
} }
} }
return nil return nil
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
"github.com/k3s-io/k3s/pkg/proctitle" "github.com/k3s-io/k3s/pkg/proctitle"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/natefinch/lumberjack" "github.com/natefinch/lumberjack"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
...@@ -46,7 +46,7 @@ func forkIfLoggingOrReaping() error { ...@@ -46,7 +46,7 @@ func forkIfLoggingOrReaping() error {
pwd, err := os.Getwd() pwd, err := os.Getwd()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get working directory") return pkgerrors.WithMessage(err, "failed to get working directory")
} }
if enableReaping { if enableReaping {
......
...@@ -92,6 +92,7 @@ type Server struct { ...@@ -92,6 +92,7 @@ type Server struct {
EtcdExposeMetrics bool EtcdExposeMetrics bool
EtcdSnapshotDir string EtcdSnapshotDir string
EtcdSnapshotCron string EtcdSnapshotCron string
EtcdSnapshotReconcile time.Duration
EtcdSnapshotRetention int EtcdSnapshotRetention int
EtcdSnapshotCompress bool EtcdSnapshotCompress bool
EtcdListFormat string EtcdListFormat string
...@@ -390,6 +391,12 @@ var ServerFlags = []cli.Flag{ ...@@ -390,6 +391,12 @@ var ServerFlags = []cli.Flag{
Destination: &ServerConfig.EtcdSnapshotCron, Destination: &ServerConfig.EtcdSnapshotCron,
Value: "0 */12 * * *", Value: "0 */12 * * *",
}, },
&cli.DurationFlag{
Name: "etcd-snapshot-reconcile-interval",
Usage: "(db) Snapshot reconcile interval",
Destination: &ServerConfig.EtcdSnapshotReconcile,
Value: 10 * time.Minute,
},
&cli.IntFlag{ &cli.IntFlag{
Name: "etcd-snapshot-retention", Name: "etcd-snapshot-retention",
Usage: "(db) Number of snapshots to retain", Usage: "(db) Number of snapshots to retain",
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
...@@ -12,7 +13,7 @@ import ( ...@@ -12,7 +13,7 @@ import (
"text/tabwriter" "text/tabwriter"
"time" "time"
k3s "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1" k3s "github.com/k3s-io/api/k3s.cattle.io/v1"
"github.com/k3s-io/k3s/pkg/cli/cmds" "github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/clientaccess" "github.com/k3s-io/k3s/pkg/clientaccess"
"github.com/k3s-io/k3s/pkg/cluster/managed" "github.com/k3s-io/k3s/pkg/cluster/managed"
...@@ -21,7 +22,7 @@ import ( ...@@ -21,7 +22,7 @@ import (
"github.com/k3s-io/k3s/pkg/proctitle" "github.com/k3s-io/k3s/pkg/proctitle"
"github.com/k3s-io/k3s/pkg/server" "github.com/k3s-io/k3s/pkg/server"
util2 "github.com/k3s-io/k3s/pkg/util" util2 "github.com/k3s-io/k3s/pkg/util"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
...@@ -92,7 +93,7 @@ func wrapServerError(err error) error { ...@@ -92,7 +93,7 @@ func wrapServerError(err error) error {
// since the operation may have actualy succeeded despite the client timing out the request. // since the operation may have actualy succeeded despite the client timing out the request.
return err return err
} }
return errors.Wrap(err, "see server log for details") return pkgerrors.WithMessage(err, "see server log for details")
} }
// Save triggers an on-demand etcd snapshot operation // Save triggers an on-demand etcd snapshot operation
......
...@@ -17,7 +17,7 @@ import ( ...@@ -17,7 +17,7 @@ import (
"github.com/k3s-io/k3s/pkg/server" "github.com/k3s-io/k3s/pkg/server"
"github.com/k3s-io/k3s/pkg/server/handlers" "github.com/k3s-io/k3s/pkg/server/handlers"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
"k8s.io/utils/ptr" "k8s.io/utils/ptr"
) )
...@@ -44,7 +44,7 @@ func commandPrep(cfg *cmds.Server) (*clientaccess.Info, error) { ...@@ -44,7 +44,7 @@ func commandPrep(cfg *cmds.Server) (*clientaccess.Info, error) {
} }
func wrapServerError(err error) error { func wrapServerError(err error) error {
return errors.Wrap(err, "see server log for details") return pkgerrors.WithMessage(err, "see server log for details")
} }
func Enable(app *cli.Context) error { func Enable(app *cli.Context) error {
......
...@@ -2,6 +2,7 @@ package server ...@@ -2,6 +2,7 @@ package server
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net" "net"
"os" "os"
...@@ -29,7 +30,7 @@ import ( ...@@ -29,7 +30,7 @@ import (
"github.com/k3s-io/k3s/pkg/util/permissions" "github.com/k3s-io/k3s/pkg/util/permissions"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/k3s-io/k3s/pkg/vpn" "github.com/k3s-io/k3s/pkg/vpn"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/wrangler/pkg/signals" "github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
...@@ -75,7 +76,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -75,7 +76,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
if !cfg.DisableAgent && !cfg.Rootless { if !cfg.DisableAgent && !cfg.Rootless {
if err := permissions.IsPrivileged(); err != nil { if err := permissions.IsPrivileged(); err != nil {
return errors.Wrap(err, "server requires additional privilege when not run with --rootless and/or --disable-agent") return pkgerrors.WithMessage(err, "server requires additional privilege when not run with --rootless and/or --disable-agent")
} }
} }
...@@ -183,12 +184,19 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -183,12 +184,19 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
serverConfig.ControlConfig.VModule = cmds.LogConfig.VModule serverConfig.ControlConfig.VModule = cmds.LogConfig.VModule
if !cfg.EtcdDisableSnapshots || cfg.ClusterReset { if !cfg.EtcdDisableSnapshots || cfg.ClusterReset {
if cfg.EtcdSnapshotReconcile <= 0 {
return errors.New("etcd-snapshot-reconcile-interval must be greater than 0s")
}
serverConfig.ControlConfig.EtcdSnapshotCompress = cfg.EtcdSnapshotCompress serverConfig.ControlConfig.EtcdSnapshotCompress = cfg.EtcdSnapshotCompress
serverConfig.ControlConfig.EtcdSnapshotName = cfg.EtcdSnapshotName serverConfig.ControlConfig.EtcdSnapshotName = cfg.EtcdSnapshotName
serverConfig.ControlConfig.EtcdSnapshotCron = cfg.EtcdSnapshotCron serverConfig.ControlConfig.EtcdSnapshotCron = cfg.EtcdSnapshotCron
serverConfig.ControlConfig.EtcdSnapshotDir = cfg.EtcdSnapshotDir serverConfig.ControlConfig.EtcdSnapshotDir = cfg.EtcdSnapshotDir
serverConfig.ControlConfig.EtcdSnapshotReconcile = metav1.Duration{Duration: cfg.EtcdSnapshotReconcile}
serverConfig.ControlConfig.EtcdSnapshotRetention = cfg.EtcdSnapshotRetention serverConfig.ControlConfig.EtcdSnapshotRetention = cfg.EtcdSnapshotRetention
if cfg.EtcdS3 { if cfg.EtcdS3 {
if cfg.EtcdS3Timeout <= 0 {
return errors.New("etcd-s3-timeout must be greater than 0s")
}
serverConfig.ControlConfig.EtcdS3 = &config.EtcdS3{ serverConfig.ControlConfig.EtcdS3 = &config.EtcdS3{
AccessKey: cfg.EtcdS3AccessKey, AccessKey: cfg.EtcdS3AccessKey,
Bucket: cfg.EtcdS3BucketName, Bucket: cfg.EtcdS3BucketName,
...@@ -327,7 +335,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -327,7 +335,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
for _, cidr := range util.SplitStringSlice(cmds.ServerConfig.ClusterCIDR) { for _, cidr := range util.SplitStringSlice(cmds.ServerConfig.ClusterCIDR) {
_, parsed, err := net.ParseCIDR(cidr) _, parsed, err := net.ParseCIDR(cidr)
if err != nil { if err != nil {
return errors.Wrapf(err, "invalid cluster-cidr %s", cidr) return pkgerrors.WithMessagef(err, "invalid cluster-cidr %s", cidr)
} }
serverConfig.ControlConfig.ClusterIPRanges = append(serverConfig.ControlConfig.ClusterIPRanges, parsed) serverConfig.ControlConfig.ClusterIPRanges = append(serverConfig.ControlConfig.ClusterIPRanges, parsed)
} }
...@@ -342,7 +350,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -342,7 +350,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
for _, cidr := range util.SplitStringSlice(cmds.ServerConfig.ServiceCIDR) { for _, cidr := range util.SplitStringSlice(cmds.ServerConfig.ServiceCIDR) {
_, parsed, err := net.ParseCIDR(cidr) _, parsed, err := net.ParseCIDR(cidr)
if err != nil { if err != nil {
return errors.Wrapf(err, "invalid service-cidr %s", cidr) return pkgerrors.WithMessagef(err, "invalid service-cidr %s", cidr)
} }
serverConfig.ControlConfig.ServiceIPRanges = append(serverConfig.ControlConfig.ServiceIPRanges, parsed) serverConfig.ControlConfig.ServiceIPRanges = append(serverConfig.ControlConfig.ServiceIPRanges, parsed)
} }
...@@ -352,7 +360,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -352,7 +360,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
serverConfig.ControlConfig.ServiceNodePortRange, err = utilnet.ParsePortRange(cfg.ServiceNodePortRange) serverConfig.ControlConfig.ServiceNodePortRange, err = utilnet.ParsePortRange(cfg.ServiceNodePortRange)
if err != nil { if err != nil {
return errors.Wrapf(err, "invalid port range %s", cfg.ServiceNodePortRange) return pkgerrors.WithMessagef(err, "invalid port range %s", cfg.ServiceNodePortRange)
} }
// the apiserver service does not yet support dual-stack operation // the apiserver service does not yet support dual-stack operation
...@@ -370,7 +378,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -370,7 +378,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
for _, svcCIDR := range serverConfig.ControlConfig.ServiceIPRanges { for _, svcCIDR := range serverConfig.ControlConfig.ServiceIPRanges {
clusterDNS, err := utilsnet.GetIndexedIP(svcCIDR, 10) clusterDNS, err := utilsnet.GetIndexedIP(svcCIDR, 10)
if err != nil { if err != nil {
return errors.Wrap(err, "cannot configure default cluster-dns address") return pkgerrors.WithMessage(err, "cannot configure default cluster-dns address")
} }
serverConfig.ControlConfig.ClusterDNSs = append(serverConfig.ControlConfig.ClusterDNSs, clusterDNS) serverConfig.ControlConfig.ClusterDNSs = append(serverConfig.ControlConfig.ClusterDNSs, clusterDNS)
} }
...@@ -420,7 +428,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -420,7 +428,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
serverConfig.ControlConfig.MinTLSVersion = tlsMinVersionArg serverConfig.ControlConfig.MinTLSVersion = tlsMinVersionArg
serverConfig.ControlConfig.TLSMinVersion, err = kubeapiserverflag.TLSVersion(tlsMinVersionArg) serverConfig.ControlConfig.TLSMinVersion, err = kubeapiserverflag.TLSVersion(tlsMinVersionArg)
if err != nil { if err != nil {
return errors.Wrap(err, "invalid tls-min-version") return pkgerrors.WithMessage(err, "invalid tls-min-version")
} }
serverConfig.StartupHooks = append(serverConfig.StartupHooks, cfg.StartupHooks...) serverConfig.StartupHooks = append(serverConfig.StartupHooks, cfg.StartupHooks...)
...@@ -450,7 +458,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -450,7 +458,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
serverConfig.ControlConfig.CipherSuites = tlsCipherSuites serverConfig.ControlConfig.CipherSuites = tlsCipherSuites
serverConfig.ControlConfig.TLSCipherSuites, err = kubeapiserverflag.TLSCipherSuites(tlsCipherSuites) serverConfig.ControlConfig.TLSCipherSuites, err = kubeapiserverflag.TLSCipherSuites(tlsCipherSuites)
if err != nil { if err != nil {
return errors.Wrap(err, "invalid tls-cipher-suites") return pkgerrors.WithMessage(err, "invalid tls-cipher-suites")
} }
// If performing a cluster reset, make sure control-plane components are // If performing a cluster reset, make sure control-plane components are
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
...@@ -19,7 +20,7 @@ import ( ...@@ -19,7 +20,7 @@ import (
"github.com/k3s-io/k3s/pkg/server/handlers" "github.com/k3s-io/k3s/pkg/server/handlers"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
...@@ -121,7 +122,7 @@ func delete(app *cli.Context, cfg *cmds.Token) error { ...@@ -121,7 +122,7 @@ func delete(app *cli.Context, cfg *cmds.Token) error {
} }
secretName := bootstraputil.BootstrapTokenSecretName(token) secretName := bootstraputil.BootstrapTokenSecretName(token)
if err := client.CoreV1().Secrets(metav1.NamespaceSystem).Delete(context.TODO(), secretName, metav1.DeleteOptions{}); err != nil { if err := client.CoreV1().Secrets(metav1.NamespaceSystem).Delete(context.TODO(), secretName, metav1.DeleteOptions{}); err != nil {
return errors.Wrapf(err, "failed to delete bootstrap token %q", err) return pkgerrors.WithMessagef(err, "failed to delete bootstrap token %q", err)
} }
fmt.Printf("bootstrap token %q deleted\n", token) fmt.Printf("bootstrap token %q deleted\n", token)
...@@ -218,7 +219,7 @@ func list(app *cli.Context, cfg *cmds.Token) error { ...@@ -218,7 +219,7 @@ func list(app *cli.Context, cfg *cmds.Token) error {
secrets, err := client.CoreV1().Secrets(metav1.NamespaceSystem).List(context.TODO(), listOptions) secrets, err := client.CoreV1().Secrets(metav1.NamespaceSystem).List(context.TODO(), listOptions)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to list bootstrap tokens") return pkgerrors.WithMessagef(err, "failed to list bootstrap tokens")
} }
tokens := make([]*kubeadm.BootstrapToken, len(secrets.Items)) tokens := make([]*kubeadm.BootstrapToken, len(secrets.Items))
......
...@@ -3,7 +3,7 @@ package clientaccess ...@@ -3,7 +3,7 @@ package clientaccess
import ( import (
"os" "os"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
) )
...@@ -12,17 +12,17 @@ import ( ...@@ -12,17 +12,17 @@ import (
func WriteClientKubeConfig(destFile, url, serverCAFile, clientCertFile, clientKeyFile string) error { func WriteClientKubeConfig(destFile, url, serverCAFile, clientCertFile, clientKeyFile string) error {
serverCA, err := os.ReadFile(serverCAFile) serverCA, err := os.ReadFile(serverCAFile)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to read %s", serverCAFile) return pkgerrors.WithMessagef(err, "failed to read %s", serverCAFile)
} }
clientCert, err := os.ReadFile(clientCertFile) clientCert, err := os.ReadFile(clientCertFile)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to read %s", clientCertFile) return pkgerrors.WithMessagef(err, "failed to read %s", clientCertFile)
} }
clientKey, err := os.ReadFile(clientKeyFile) clientKey, err := os.ReadFile(clientKeyFile)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to read %s", clientKeyFile) return pkgerrors.WithMessagef(err, "failed to read %s", clientKeyFile)
} }
config := clientcmdapi.NewConfig() config := clientcmdapi.NewConfig()
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"crypto/x509" "crypto/x509"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
...@@ -16,7 +17,7 @@ import ( ...@@ -16,7 +17,7 @@ import (
"time" "time"
"github.com/k3s-io/k3s/pkg/kubeadm" "github.com/k3s-io/k3s/pkg/kubeadm"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
certutil "github.com/rancher/dynamiclistener/cert" certutil "github.com/rancher/dynamiclistener/cert"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
...@@ -67,8 +68,29 @@ type Info struct { ...@@ -67,8 +68,29 @@ type Info struct {
// ValidationOption is a callback to mutate the token prior to use // ValidationOption is a callback to mutate the token prior to use
type ValidationOption func(*Info) type ValidationOption func(*Info)
// WithCACertificate overrides the CA cert and hash with certs loaded from the
// provided file. It is not an error if the file doesn't exist; the client
// will just follow the normal hash validation steps if so.
func WithCACertificate(certFile string) ValidationOption {
return func(i *Info) {
cacerts, err := os.ReadFile(certFile)
if err != nil {
return
}
digest, _ := hashCA(cacerts)
if i.caHash != "" && i.caHash != digest {
return
}
i.caHash = digest
i.CACerts = cacerts
}
}
// WithClientCertificate configures certs and keys to be used // WithClientCertificate configures certs and keys to be used
// to authenticate the request. // to authenticate the request. It is not an error if the files do not
// exist, client cert auth will not be attempted if so.
func WithClientCertificate(certFile, keyFile string) ValidationOption { func WithClientCertificate(certFile, keyFile string) ValidationOption {
return func(i *Info) { return func(i *Info) {
i.CertFile = certFile i.CertFile = certFile
...@@ -338,11 +360,12 @@ func (i *Info) Post(path string, body []byte, options ...any) ([]byte, error) { ...@@ -338,11 +360,12 @@ func (i *Info) Post(path string, body []byte, options ...any) ([]byte, error) {
} }
// setServer sets the BaseURL and CACerts fields of the Info by connecting to the server // setServer sets the BaseURL and CACerts fields of the Info by connecting to the server
// and storing the CA bundle. // and storing the CA bundle. If CACerts has already been set via ValidationOption,
// retrieval is skipped.
func (i *Info) setServer(server string) error { func (i *Info) setServer(server string) error {
url, err := url.Parse(server) url, err := url.Parse(server)
if err != nil { if err != nil {
return errors.Wrapf(err, "Invalid server url, failed to parse: %s", server) return pkgerrors.WithMessagef(err, "Invalid server url, failed to parse: %s", server)
} }
if url.Scheme != "https" { if url.Scheme != "https" {
...@@ -353,13 +376,15 @@ func (i *Info) setServer(server string) error { ...@@ -353,13 +376,15 @@ func (i *Info) setServer(server string) error {
url.Path = url.Path[:len(url.Path)-1] url.Path = url.Path[:len(url.Path)-1]
} }
cacerts, err := getCACerts(*url) if len(i.CACerts) == 0 {
if err != nil { cacerts, err := getCACerts(*url)
return err if err != nil {
return err
}
i.CACerts = cacerts
} }
i.BaseURL = url.String() i.BaseURL = url.String()
i.CACerts = cacerts
return nil return nil
} }
...@@ -400,7 +425,7 @@ func getCACerts(u url.URL) ([]byte, error) { ...@@ -400,7 +425,7 @@ func getCACerts(u url.URL) ([]byte, error) {
// Download the CA bundle using a client that does not validate certs. // Download the CA bundle using a client that does not validate certs.
cacerts, err := get(url, insecureClient, "", "", "") cacerts, err := get(url, insecureClient, "", "", "")
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to get CA certs") return nil, pkgerrors.WithMessage(err, "failed to get CA certs")
} }
// Request the CA bundle again, validating that the CA bundle can be loaded // Request the CA bundle again, validating that the CA bundle can be loaded
...@@ -408,7 +433,7 @@ func getCACerts(u url.URL) ([]byte, error) { ...@@ -408,7 +433,7 @@ func getCACerts(u url.URL) ([]byte, error) {
// get an empty CA bundle. or if the dynamiclistener cert is incorrectly signed. // get an empty CA bundle. or if the dynamiclistener cert is incorrectly signed.
_, err = get(url, GetHTTPClient(cacerts, "", ""), "", "", "") _, err = get(url, GetHTTPClient(cacerts, "", ""), "", "", "")
if err != nil { if err != nil {
return nil, errors.Wrap(err, "CA cert validation failed") return nil, pkgerrors.WithMessage(err, "CA cert validation failed")
} }
return cacerts, nil return cacerts, nil
......
...@@ -2,22 +2,22 @@ package cloudprovider ...@@ -2,22 +2,22 @@ package cloudprovider
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
cloudprovider "k8s.io/cloud-provider" cloudprovider "k8s.io/cloud-provider"
) )
var ( var (
InternalIPKey = version.Program + ".io/internal-ip" InternalIPKey = version.Program + ".io/internal-ip"
ExternalIPKey = version.Program + ".io/external-ip" ExternalIPKey = version.Program + ".io/external-ip"
InternalDNSKey = version.Program + ".io/internal-dns" InternalDNSKey = version.Program + ".io/internal-dns"
ExternalDNSKey = version.Program + ".io/external-dns" ExternalDNSKey = version.Program + ".io/external-dns"
HostnameKey = version.Program + ".io/hostname" HostnameKey = version.Program + ".io/hostname"
) )
var _ cloudprovider.InstancesV2 = &k3s{} var _ cloudprovider.InstancesV2 = &k3s{}
......
...@@ -3,7 +3,6 @@ package cluster ...@@ -3,7 +3,6 @@ package cluster
import ( import (
"context" "context"
"net/url" "net/url"
"runtime"
"strings" "strings"
"time" "time"
...@@ -12,7 +11,7 @@ import ( ...@@ -12,7 +11,7 @@ import (
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/etcd" "github.com/k3s-io/k3s/pkg/etcd"
"github.com/k3s-io/kine/pkg/endpoint" "github.com/k3s-io/kine/pkg/endpoint"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
utilsnet "k8s.io/utils/net" utilsnet "k8s.io/utils/net"
...@@ -25,7 +24,6 @@ type Cluster struct { ...@@ -25,7 +24,6 @@ type Cluster struct {
joining bool joining bool
storageStarted bool storageStarted bool
saveBootstrap bool saveBootstrap bool
shouldBootstrap bool
cnFilterFunc func(...string) []string cnFilterFunc func(...string) []string
} }
...@@ -36,104 +34,70 @@ type Cluster struct { ...@@ -36,104 +34,70 @@ type Cluster struct {
func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) { func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
// Set up the dynamiclistener and http request handlers // Set up the dynamiclistener and http request handlers
if err := c.initClusterAndHTTPS(ctx); err != nil { if err := c.initClusterAndHTTPS(ctx); err != nil {
return nil, errors.Wrap(err, "init cluster datastore and https") return nil, pkgerrors.WithMessage(err, "init cluster datastore and https")
} }
if c.config.DisableETCD { if c.config.DisableETCD {
ready := make(chan struct{}) ready := make(chan struct{})
defer close(ready) defer close(ready)
// try to get /db/info urls first, for a current list of etcd cluster member client URLs
clientURLs, _, err := etcd.ClientURLs(ctx, c.clientAccessInfo, c.config.PrivateIP)
if err != nil {
return nil, err
}
// If we somehow got no error but also no client URLs, just use the address of the server we're joining
if len(clientURLs) == 0 {
clientURL, err := url.Parse(c.config.JoinURL)
if err != nil {
return nil, err
}
clientURL.Host = clientURL.Hostname() + ":2379"
clientURLs = append(clientURLs, clientURL.String())
logrus.Warnf("Got empty etcd ClientURL list; using server URL %s", clientURL)
}
etcdProxy, err := etcd.NewETCDProxy(ctx, c.config.SupervisorPort, c.config.DataDir, clientURLs[0], utilsnet.IsIPv6CIDR(c.config.ServiceIPRanges[0]))
if err != nil {
return nil, err
}
// immediately update the load balancer with all etcd addresses
// client URLs are a full URI, but the proxy only wants host:port
for i, c := range clientURLs {
u, err := url.Parse(c)
if err != nil {
return nil, errors.Wrap(err, "failed to parse etcd ClientURL")
}
clientURLs[i] = u.Host
}
etcdProxy.Update(clientURLs)
// start periodic endpoint sync goroutine
c.setupEtcdProxy(ctx, etcdProxy)
// remove etcd member if it exists
if err := c.managedDB.RemoveSelf(ctx); err != nil {
logrus.Warnf("Failed to remove this node from etcd members")
}
c.config.Runtime.EtcdConfig.Endpoints = strings.Split(c.config.Datastore.Endpoint, ",")
c.config.Runtime.EtcdConfig.TLSConfig = c.config.Datastore.BackendTLSConfig
return ready, nil return ready, nil
} }
// start managed database (if necessary) // start managed etcd database; when kine is in use this is a no-op.
if err := c.start(ctx); err != nil { if err := c.start(ctx); err != nil {
return nil, errors.Wrap(err, "start managed database") return nil, pkgerrors.WithMessage(err, "start managed database")
} }
// get the wait channel for testing managed database readiness // get the wait channel for testing etcd server readiness; when kine is in
ready, err := c.testClusterDB(ctx) // use the channel is closed immediately.
if err != nil { ready := c.testClusterDB(ctx)
return nil, err
}
// set c.config.Datastore and c.config.Runtime.EtcdConfig with values
// necessary to build etcd clients, and start kine listener if necessary.
if err := c.startStorage(ctx, false); err != nil { if err := c.startStorage(ctx, false); err != nil {
return nil, err return nil, err
} }
// if necessary, store bootstrap data to datastore // if necessary, store bootstrap data to datastore. saveBootstrap is only set
// when using kine, so this can be done before the ready channel has been closed.
if c.saveBootstrap { if c.saveBootstrap {
if err := Save(ctx, c.config, false); err != nil { if err := Save(ctx, c.config, false); err != nil {
return nil, err return nil, err
} }
} }
// at this point, if etcd is in use, it's bootstrapping is complete
// so save the bootstrap data. We will need for etcd to be up. If
// the save call returns an error, we panic since subsequent etcd
// snapshots will be empty.
if c.managedDB != nil { if c.managedDB != nil {
go func() { go func() {
for { for {
select { select {
case <-ready: case <-ready:
// always save to managed etcd, to ensure that any file modified locally are in sync with the datastore.
// this will panic if multiple keys exist, to prevent nodes from running with different bootstrap data.
if err := Save(ctx, c.config, false); err != nil { if err := Save(ctx, c.config, false); err != nil {
panic(err) panic(err)
} }
if !c.config.EtcdDisableSnapshots { if !c.config.EtcdDisableSnapshots {
_ = wait.PollUntilContextCancel(ctx, time.Second, true, func(ctx context.Context) (bool, error) { // do an initial reconcile of snapshots with a fast retry until it succeeds
err := c.managedDB.ReconcileSnapshotData(ctx) wait.PollUntilContextCancel(ctx, time.Second, true, func(ctx context.Context) (bool, error) {
if err != nil { if err := c.managedDB.ReconcileSnapshotData(ctx); err != nil {
logrus.Errorf("Failed to record snapshots for cluster: %v", err) logrus.Errorf("Failed to record snapshots for cluster: %v", err)
return false, nil
} }
return err == nil, nil return true, nil
}) })
// continue reconciling snapshots in the background at the configured interval.
// the interval is jittered by 5% to avoid all nodes reconciling at the same time.
wait.JitterUntilWithContext(ctx, func(ctx context.Context) {
if err := c.managedDB.ReconcileSnapshotData(ctx); err != nil {
logrus.Errorf("Failed to record snapshots for cluster: %v", err)
}
}, c.config.EtcdSnapshotReconcile.Duration, 0.05, false)
} }
return return
default: case <-ctx.Done():
runtime.Gosched() return
} }
} }
}() }()
...@@ -142,6 +106,49 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) { ...@@ -142,6 +106,49 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
return ready, nil return ready, nil
} }
// startEtcdProxy starts an etcd load-balancer proxy, for control-plane-only nodes
// without a local datastore.
func (c *Cluster) startEtcdProxy(ctx context.Context) error {
defaultURL, err := url.Parse(c.config.JoinURL)
if err != nil {
return err
}
defaultURL.Host = defaultURL.Hostname() + ":2379"
etcdProxy, err := etcd.NewETCDProxy(ctx, c.config.SupervisorPort, c.config.DataDir, defaultURL.String(), utilsnet.IsIPv6CIDR(c.config.ServiceIPRanges[0]))
if err != nil {
return err
}
// immediately update the load balancer with all etcd addresses
// from /db/info, for a current list of etcd cluster member client URLs.
// client URLs are a full URI, but the proxy only wants host:port
if clientURLs, _, err := etcd.ClientURLs(ctx, c.clientAccessInfo, c.config.PrivateIP); err != nil || len(clientURLs) == 0 {
logrus.Warnf("Failed to get etcd ClientURLs: %v", err)
} else {
for i, c := range clientURLs {
u, err := url.Parse(c)
if err != nil {
return pkgerrors.WithMessage(err, "failed to parse etcd ClientURL")
}
clientURLs[i] = u.Host
}
etcdProxy.Update(clientURLs)
}
// start periodic endpoint sync goroutine
c.setupEtcdProxy(ctx, etcdProxy)
// remove etcd member if it exists
if err := c.managedDB.RemoveSelf(ctx); err != nil {
logrus.Warnf("Failed to remove this node from etcd members: %v", err)
}
c.config.Runtime.EtcdConfig.Endpoints = strings.Split(c.config.Datastore.Endpoint, ",")
c.config.Runtime.EtcdConfig.TLSConfig = c.config.Datastore.BackendTLSConfig
return nil
}
// startStorage starts the kine listener and configures the endpoints, if necessary. // startStorage starts the kine listener and configures the endpoints, if necessary.
// This calls into the kine endpoint code, which sets up the database client // This calls into the kine endpoint code, which sets up the database client
// and unix domain socket listener if using an external database. In the case of an etcd // and unix domain socket listener if using an external database. In the case of an etcd
...@@ -162,7 +169,7 @@ func (c *Cluster) startStorage(ctx context.Context, bootstrap bool) error { ...@@ -162,7 +169,7 @@ func (c *Cluster) startStorage(ctx context.Context, bootstrap bool) error {
// start listening on the kine socket as an etcd endpoint, or return the external etcd endpoints // start listening on the kine socket as an etcd endpoint, or return the external etcd endpoints
etcdConfig, err := endpoint.Listen(ctx, c.config.Datastore) etcdConfig, err := endpoint.Listen(ctx, c.config.Datastore)
if err != nil { if err != nil {
return errors.Wrap(err, "creating storage endpoint") return pkgerrors.WithMessage(err, "creating storage endpoint")
} }
// Persist the returned etcd configuration. We decide if we're doing leader election for embedded controllers // Persist the returned etcd configuration. We decide if we're doing leader election for embedded controllers
......
...@@ -5,14 +5,13 @@ package cluster ...@@ -5,14 +5,13 @@ package cluster
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"time" "time"
"github.com/pkg/errors"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/k3s-io/k3s/pkg/cluster/managed" "github.com/k3s-io/k3s/pkg/cluster/managed"
"github.com/k3s-io/k3s/pkg/etcd" "github.com/k3s-io/k3s/pkg/etcd"
...@@ -26,11 +25,11 @@ import ( ...@@ -26,11 +25,11 @@ import (
// testClusterDB returns a channel that will be closed when the datastore connection is available. // testClusterDB returns a channel that will be closed when the datastore connection is available.
// The datastore is tested for readiness every 5 seconds until the test succeeds. // The datastore is tested for readiness every 5 seconds until the test succeeds.
func (c *Cluster) testClusterDB(ctx context.Context) (<-chan struct{}, error) { func (c *Cluster) testClusterDB(ctx context.Context) <-chan struct{} {
result := make(chan struct{}) result := make(chan struct{})
if c.managedDB == nil { if c.managedDB == nil {
close(result) close(result)
return result, nil return result
} }
go func() { go func() {
...@@ -51,7 +50,7 @@ func (c *Cluster) testClusterDB(ctx context.Context) (<-chan struct{}, error) { ...@@ -51,7 +50,7 @@ func (c *Cluster) testClusterDB(ctx context.Context) (<-chan struct{}, error) {
} }
}() }()
return result, nil return result
} }
// start starts the database, unless a cluster reset has been requested, in which case // start starts the database, unless a cluster reset has been requested, in which case
......
...@@ -198,8 +198,12 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error { ...@@ -198,8 +198,12 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error {
attempts := 0 attempts := 0
tokenKey := storageKey(normalizedToken) tokenKey := storageKey(normalizedToken)
return wait.PollUntilContextCancel(ctx, time.Second, true, func(ctx context.Context) (bool, error) { return wait.PollUntilContextCancel(ctx, 5*time.Second, true, func(ctx context.Context) (bool, error) {
attempts++ attempts++
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
value, saveBootstrap, err := getBootstrapKeyFromStorage(ctx, storageClient, normalizedToken, token) value, saveBootstrap, err := getBootstrapKeyFromStorage(ctx, storageClient, normalizedToken, token)
c.saveBootstrap = saveBootstrap c.saveBootstrap = saveBootstrap
if err != nil { if err != nil {
...@@ -246,6 +250,25 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error { ...@@ -246,6 +250,25 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error {
}) })
} }
// getBootstrapData makes a single attempt to retrieve and decrypt bootstrap data from the datastore.
func (c *Cluster) getBootstrapData(ctx context.Context, token string) ([]byte, error) {
storageClient, err := client.New(c.config.Runtime.EtcdConfig)
if err != nil {
return nil, err
}
defer storageClient.Close()
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
value, err := storageClient.Get(ctx, storageKey(token))
if err != nil {
return nil, err
}
return decrypt(token, value.Data)
}
// getBootstrapKeyFromStorage will list all keys that has prefix /bootstrap and will check for key that is // getBootstrapKeyFromStorage will list all keys that has prefix /bootstrap and will check for key that is
// hashed with empty string and will check for any key that is hashed by different token than the one // hashed with empty string and will check for any key that is hashed by different token than the one
// passed to it, it will return error if it finds a key that is hashed with different token and will return // passed to it, it will return error if it finds a key that is hashed with different token and will return
......
package main
import (
"github.com/rancher/wrangler/pkg/cleanup"
"github.com/sirupsen/logrus"
)
func main() {
if err := cleanup.Cleanup("./pkg/apis"); err != nil {
logrus.Fatal(err)
}
}
...@@ -4,16 +4,9 @@ import ( ...@@ -4,16 +4,9 @@ import (
"os" "os"
bindata "github.com/go-bindata/go-bindata" bindata "github.com/go-bindata/go-bindata"
v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
controllergen "github.com/rancher/wrangler/pkg/controller-gen"
"github.com/rancher/wrangler/pkg/controller-gen/args"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var (
basePackage = "github.com/k3s-io/k3s/types"
)
func main() { func main() {
os.Unsetenv("GOPATH") os.Unsetenv("GOPATH")
bc := &bindata.Config{ bc := &bindata.Config{
...@@ -66,19 +59,4 @@ func main() { ...@@ -66,19 +59,4 @@ func main() {
if err := bindata.Translate(bc); err != nil { if err := bindata.Translate(bc); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
controllergen.Run(args.Options{
OutputPackage: "github.com/k3s-io/k3s/pkg/generated",
Boilerplate: "scripts/boilerplate.go.txt",
Groups: map[string]args.Group{
"k3s.cattle.io": {
Types: []interface{}{
v1.Addon{},
v1.ETCDSnapshotFile{},
},
GenerateTypes: true,
GenerateClients: true,
},
},
})
} }
...@@ -5,17 +5,17 @@ package containerd ...@@ -5,17 +5,17 @@ package containerd
import ( import (
util2 "github.com/k3s-io/k3s/pkg/util" util2 "github.com/k3s-io/k3s/pkg/util"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
) )
func OverlaySupported(root string) error { func OverlaySupported(root string) error {
return errors.Wrapf(util2.ErrUnsupportedPlatform, "overlayfs is not supported") return pkgerrors.WithMessagef(util2.ErrUnsupportedPlatform, "overlayfs is not supported")
} }
func FuseoverlayfsSupported(root string) error { func FuseoverlayfsSupported(root string) error {
return errors.Wrapf(util2.ErrUnsupportedPlatform, "fuse-overlayfs is not supported") return pkgerrors.WithMessagef(util2.ErrUnsupportedPlatform, "fuse-overlayfs is not supported")
} }
func StargzSupported(root string) error { func StargzSupported(root string) error {
return errors.Wrapf(util2.ErrUnsupportedPlatform, "stargz is not supported") return pkgerrors.WithMessagef(util2.ErrUnsupportedPlatform, "stargz is not supported")
} }
package crd package crd
import ( import (
v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1" v1 "github.com/k3s-io/api/k3s.cattle.io/v1"
"github.com/rancher/wrangler/pkg/crd" "github.com/rancher/wrangler/pkg/crd"
) )
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/k3s-io/k3s/pkg/agent/proxy" "github.com/k3s-io/k3s/pkg/agent/proxy"
daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config" daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/daemons/executor" "github.com/k3s-io/k3s/pkg/daemons/executor"
pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"k8s.io/component-base/logs" "k8s.io/component-base/logs"
logsapi "k8s.io/component-base/logs/api/v1" logsapi "k8s.io/component-base/logs/api/v1"
...@@ -24,7 +25,7 @@ func Agent(ctx context.Context, nodeConfig *daemonconfig.Node, proxy proxy.Proxy ...@@ -24,7 +25,7 @@ func Agent(ctx context.Context, nodeConfig *daemonconfig.Node, proxy proxy.Proxy
defer logs.FlushLogs() defer logs.FlushLogs()
if err := startKubelet(ctx, &nodeConfig.AgentConfig); err != nil { if err := startKubelet(ctx, &nodeConfig.AgentConfig); err != nil {
return err return pkgerrors.WithMessage(err, "failed to start kubelet")
} }
go func() { go func() {
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/k3s-io/k3s/pkg/generated/controllers/k3s.cattle.io" "github.com/k3s-io/api/pkg/generated/controllers/k3s.cattle.io"
"github.com/k3s-io/kine/pkg/endpoint" "github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/wharfie/pkg/registries" "github.com/rancher/wharfie/pkg/registries"
"github.com/rancher/wrangler/pkg/generated/controllers/core" "github.com/rancher/wrangler/pkg/generated/controllers/core"
...@@ -233,17 +233,18 @@ type Control struct { ...@@ -233,17 +233,18 @@ type Control struct {
ClusterResetRestorePath string ClusterResetRestorePath string
MinTLSVersion string MinTLSVersion string
CipherSuites []string CipherSuites []string
TLSMinVersion uint16 `json:"-"` TLSMinVersion uint16 `json:"-"`
TLSCipherSuites []uint16 `json:"-"` TLSCipherSuites []uint16 `json:"-"`
EtcdSnapshotName string `json:"-"` EtcdSnapshotName string `json:"-"`
EtcdDisableSnapshots bool `json:"-"` EtcdDisableSnapshots bool `json:"-"`
EtcdExposeMetrics bool `json:"-"` EtcdExposeMetrics bool `json:"-"`
EtcdSnapshotDir string `json:"-"` EtcdSnapshotDir string `json:"-"`
EtcdSnapshotCron string `json:"-"` EtcdSnapshotCron string `json:"-"`
EtcdSnapshotRetention int `json:"-"` EtcdSnapshotReconcile metav1.Duration `json:"-"`
EtcdSnapshotCompress bool `json:"-"` EtcdSnapshotRetention int `json:"-"`
EtcdListFormat string `json:"-"` EtcdSnapshotCompress bool `json:"-"`
EtcdS3 *EtcdS3 `json:"-"` EtcdListFormat string `json:"-"`
EtcdS3 *EtcdS3 `json:"-"`
ServerNodeName string ServerNodeName string
VLevel int VLevel int
VModule string VModule string
...@@ -310,7 +311,6 @@ type ControlRuntimeBootstrap struct { ...@@ -310,7 +311,6 @@ type ControlRuntimeBootstrap struct {
type ControlRuntime struct { type ControlRuntime struct {
ControlRuntimeBootstrap ControlRuntimeBootstrap
HTTPBootstrap bool
APIServerReady <-chan struct{} APIServerReady <-chan struct{}
ContainerRuntimeReady <-chan struct{} ContainerRuntimeReady <-chan struct{}
ETCDReady <-chan struct{} ETCDReady <-chan struct{}
...@@ -340,6 +340,7 @@ type ControlRuntime struct { ...@@ -340,6 +340,7 @@ type ControlRuntime struct {
AgentToken string AgentToken string
APIServer http.Handler APIServer http.Handler
Handler http.Handler Handler http.Handler
HTTPBootstrap http.Handler
Tunnel http.Handler Tunnel http.Handler
Authenticator authenticator.Request Authenticator authenticator.Request
......
package proxy package proxy
import ( import (
"errors"
"io" "io"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -43,12 +44,12 @@ func (p *proxy) pipe(src, dst io.ReadWriter) { ...@@ -43,12 +44,12 @@ func (p *proxy) pipe(src, dst io.ReadWriter) {
for { for {
n, err := src.Read(buff) n, err := src.Read(buff)
if err != nil { if err != nil {
p.err(errors.Wrap(err, "read failed")) p.err(pkgerrors.WithMessage(err, "read failed"))
return return
} }
_, err = dst.Write(buff[:n]) _, err = dst.Write(buff[:n])
if err != nil { if err != nil {
p.err(errors.Wrap(err, "write failed")) p.err(pkgerrors.WithMessage(err, "write failed"))
return return
} }
} }
......
...@@ -2,6 +2,7 @@ package control ...@@ -2,6 +2,7 @@ package control
import ( import (
"context" "context"
"errors"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
...@@ -16,7 +17,7 @@ import ( ...@@ -16,7 +17,7 @@ import (
"github.com/k3s-io/k3s/pkg/daemons/executor" "github.com/k3s-io/k3s/pkg/daemons/executor"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
authorizationv1 "k8s.io/api/authorization/v1" authorizationv1 "k8s.io/api/authorization/v1"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
...@@ -40,12 +41,12 @@ func Server(ctx context.Context, cfg *config.Control) error { ...@@ -40,12 +41,12 @@ func Server(ctx context.Context, cfg *config.Control) error {
logsapi.ReapplyHandling = logsapi.ReapplyHandlingIgnoreUnchanged logsapi.ReapplyHandling = logsapi.ReapplyHandlingIgnoreUnchanged
if err := prepare(ctx, cfg); err != nil { if err := prepare(ctx, cfg); err != nil {
return errors.Wrap(err, "preparing server") return pkgerrors.WithMessage(err, "preparing server")
} }
tunnel, err := setupTunnel(ctx, cfg) tunnel, err := setupTunnel(ctx, cfg)
if err != nil { if err != nil {
return errors.Wrap(err, "setup tunnel server") return pkgerrors.WithMessage(err, "setup tunnel server")
} }
cfg.Runtime.Tunnel = tunnel cfg.Runtime.Tunnel = tunnel
...@@ -287,17 +288,16 @@ func defaults(config *config.Control) { ...@@ -287,17 +288,16 @@ func defaults(config *config.Control) {
} }
func prepare(ctx context.Context, config *config.Control) error { func prepare(ctx context.Context, config *config.Control) error {
var err error
defaults(config) defaults(config)
if err := os.MkdirAll(config.DataDir, 0700); err != nil { if err := os.MkdirAll(config.DataDir, 0700); err != nil {
return err return err
} }
config.DataDir, err = filepath.Abs(config.DataDir) if dataDir, err := filepath.Abs(config.DataDir); err != nil {
if err != nil {
return err return err
} else {
config.DataDir = dataDir
} }
os.MkdirAll(filepath.Join(config.DataDir, "etc"), 0700) os.MkdirAll(filepath.Join(config.DataDir, "etc"), 0700)
...@@ -308,19 +308,19 @@ func prepare(ctx context.Context, config *config.Control) error { ...@@ -308,19 +308,19 @@ func prepare(ctx context.Context, config *config.Control) error {
cluster := cluster.New(config) cluster := cluster.New(config)
if err := cluster.Bootstrap(ctx, config.ClusterReset); err != nil { if err := cluster.Bootstrap(ctx, config.ClusterReset); err != nil {
return err return pkgerrors.WithMessage(err, "failed to bootstrap cluster data")
} }
if err := deps.GenServerDeps(config); err != nil { if err := deps.GenServerDeps(config); err != nil {
return err return pkgerrors.WithMessage(err, "failed to generate server dependencies")
} }
ready, err := cluster.Start(ctx) if ready, err := cluster.Start(ctx); err != nil {
if err != nil { return pkgerrors.WithMessage(err, "failed to start cluster")
return err } else {
config.Runtime.ETCDReady = ready
} }
config.Runtime.ETCDReady = ready
return nil return nil
} }
...@@ -515,7 +515,7 @@ func waitForUntaintedNode(ctx context.Context, kubeConfig string) error { ...@@ -515,7 +515,7 @@ func waitForUntaintedNode(ctx context.Context, kubeConfig string) error {
} }
if _, err := toolswatch.UntilWithSync(ctx, lw, &v1.Node{}, nil, condition); err != nil { if _, err := toolswatch.UntilWithSync(ctx, lw, &v1.Node{}, nil, condition); err != nil {
return errors.Wrap(err, "failed to wait for untainted node") return pkgerrors.WithMessage(err, "failed to wait for untainted node")
} }
return nil return nil
} }
......
...@@ -3,6 +3,7 @@ package control ...@@ -3,6 +3,7 @@ package control
import ( import (
"bufio" "bufio"
"context" "context"
"errors"
"io" "io"
"net" "net"
"net/http" "net/http"
...@@ -15,7 +16,6 @@ import ( ...@@ -15,7 +16,6 @@ import (
"github.com/k3s-io/k3s/pkg/nodeconfig" "github.com/k3s-io/k3s/pkg/nodeconfig"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors"
"github.com/rancher/remotedialer" "github.com/rancher/remotedialer"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/yl2chen/cidranger" "github.com/yl2chen/cidranger"
......
...@@ -5,6 +5,7 @@ package executor ...@@ -5,6 +5,7 @@ package executor
import ( import (
"context" "context"
"errors"
"flag" "flag"
"net/http" "net/http"
"os" "os"
...@@ -18,7 +19,6 @@ import ( ...@@ -18,7 +19,6 @@ import (
daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config" daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/authentication/authenticator"
cloudprovider "k8s.io/cloud-provider" cloudprovider "k8s.io/cloud-provider"
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"github.com/k3s-io/k3s/pkg/util/permissions" "github.com/k3s-io/k3s/pkg/util/permissions"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/wrangler/pkg/resolvehome" "github.com/rancher/wrangler/pkg/resolvehome"
) )
...@@ -31,7 +31,7 @@ func LocalHome(dataDir string, forceLocal bool) (string, error) { ...@@ -31,7 +31,7 @@ func LocalHome(dataDir string, forceLocal bool) (string, error) {
dataDir, err := resolvehome.Resolve(dataDir) dataDir, err := resolvehome.Resolve(dataDir)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "resolving %s", dataDir) return "", pkgerrors.WithMessagef(err, "resolving %s", dataDir)
} }
return filepath.Abs(dataDir) return filepath.Abs(dataDir)
......
...@@ -15,11 +15,11 @@ import ( ...@@ -15,11 +15,11 @@ import (
"sync" "sync"
"time" "time"
apisv1 "github.com/k3s-io/api/k3s.cattle.io/v1"
controllersv1 "github.com/k3s-io/api/pkg/generated/controllers/k3s.cattle.io/v1"
"github.com/k3s-io/k3s/pkg/agent/util" "github.com/k3s-io/k3s/pkg/agent/util"
apisv1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
controllersv1 "github.com/k3s-io/k3s/pkg/generated/controllers/k3s.cattle.io/v1"
pkgutil "github.com/k3s-io/k3s/pkg/util" pkgutil "github.com/k3s-io/k3s/pkg/util"
errors2 "github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/wrangler/pkg/apply" "github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/kv" "github.com/rancher/wrangler/pkg/kv"
"github.com/rancher/wrangler/pkg/merr" "github.com/rancher/wrangler/pkg/merr"
...@@ -165,7 +165,7 @@ func (w *watcher) listFilesIn(base string, force bool) error { ...@@ -165,7 +165,7 @@ func (w *watcher) listFilesIn(base string, force bool) error {
// Disabled files are not just skipped, but actively deleted from the filesystem // Disabled files are not just skipped, but actively deleted from the filesystem
if shouldDisableFile(base, path, w.disables) { if shouldDisableFile(base, path, w.disables) {
if err := w.delete(path); err != nil { if err := w.delete(path); err != nil {
errs = append(errs, errors2.Wrapf(err, "failed to delete %s", path)) errs = append(errs, pkgerrors.WithMessagef(err, "failed to delete %s", path))
} }
continue continue
} }
...@@ -178,7 +178,7 @@ func (w *watcher) listFilesIn(base string, force bool) error { ...@@ -178,7 +178,7 @@ func (w *watcher) listFilesIn(base string, force bool) error {
continue continue
} }
if err := w.deploy(path, !force); err != nil { if err := w.deploy(path, !force); err != nil {
errs = append(errs, errors2.Wrapf(err, "failed to process %s", path)) errs = append(errs, pkgerrors.WithMessagef(err, "failed to process %s", path))
} else { } else {
w.modTime[path] = modTime w.modTime[path] = modTime
} }
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -38,7 +38,7 @@ staging: ...@@ -38,7 +38,7 @@ staging:
os.MkdirAll(filepath.Dir(p), 0700) os.MkdirAll(filepath.Dir(p), 0700)
logrus.Info("Writing manifest: ", p) logrus.Info("Writing manifest: ", p)
if err := os.WriteFile(p, content, 0600); err != nil { if err := os.WriteFile(p, content, 0600); err != nil {
return errors.Wrapf(err, "failed to write to %s", name) return pkgerrors.WithMessagef(err, "failed to write to %s", name)
} }
} }
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io/fs" "io/fs"
"net" "net"
...@@ -33,7 +34,7 @@ import ( ...@@ -33,7 +34,7 @@ import (
"github.com/k3s-io/kine/pkg/client" "github.com/k3s-io/kine/pkg/client"
endpoint2 "github.com/k3s-io/kine/pkg/endpoint" endpoint2 "github.com/k3s-io/kine/pkg/endpoint"
cp "github.com/otiai10/copy" cp "github.com/otiai10/copy"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
certutil "github.com/rancher/dynamiclistener/cert" certutil "github.com/rancher/dynamiclistener/cert"
controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/rancher/wrangler/pkg/start" "github.com/rancher/wrangler/pkg/start"
...@@ -215,7 +216,7 @@ func (e *ETCD) Test(ctx context.Context) error { ...@@ -215,7 +216,7 @@ func (e *ETCD) Test(ctx context.Context) error {
status, err := e.status(ctx) status, err := e.status(ctx)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get etcd status") return pkgerrors.WithMessage(err, "failed to get etcd status")
} else if status.IsLearner { } else if status.IsLearner {
return errors.New("this server has not yet been promoted from learner to voting member") return errors.New("this server has not yet been promoted from learner to voting member")
} else if status.Leader == 0 { } else if status.Leader == 0 {
...@@ -229,19 +230,19 @@ func (e *ETCD) Test(ctx context.Context) error { ...@@ -229,19 +230,19 @@ func (e *ETCD) Test(ctx context.Context) error {
// defrag this node to reclaim freed space from compacted revisions // defrag this node to reclaim freed space from compacted revisions
if err := e.defragment(ctx); err != nil { if err := e.defragment(ctx); err != nil {
return errors.Wrap(err, "failed to defragment etcd database") return pkgerrors.WithMessage(err, "failed to defragment etcd database")
} }
// clear alarms on this node // clear alarms on this node
if err := e.clearAlarms(ctx, status.Header.MemberId); err != nil { if err := e.clearAlarms(ctx, status.Header.MemberId); err != nil {
return errors.Wrap(err, "failed to disarm etcd alarms") return pkgerrors.WithMessage(err, "failed to disarm etcd alarms")
} }
// refresh status - note that errors may remain on other nodes, but this // refresh status - note that errors may remain on other nodes, but this
// should not prevent us from continuing with startup. // should not prevent us from continuing with startup.
status, err = e.status(ctx) status, err = e.status(ctx)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get etcd status") return pkgerrors.WithMessage(err, "failed to get etcd status")
} }
logrus.Infof("Datastore using %d of %d bytes after defragment", status.DbSizeInUse, status.DbSize) logrus.Infof("Datastore using %d of %d bytes after defragment", status.DbSizeInUse, status.DbSize)
...@@ -334,7 +335,7 @@ func (e *ETCD) IsInitialized() (bool, error) { ...@@ -334,7 +335,7 @@ func (e *ETCD) IsInitialized() (bool, error) {
} else if os.IsNotExist(err) { } else if os.IsNotExist(err) {
return false, nil return false, nil
} else { } else {
return false, errors.Wrap(err, "invalid state for wal directory "+dir) return false, pkgerrors.WithMessage(err, "invalid state for wal directory "+dir)
} }
} }
...@@ -410,16 +411,16 @@ func (e *ETCD) Reset(ctx context.Context, rebootstrap func() error) error { ...@@ -410,16 +411,16 @@ func (e *ETCD) Reset(ctx context.Context, rebootstrap func() error) error {
if errors.Is(err, s3.ErrNoConfigSecret) { if errors.Is(err, s3.ErrNoConfigSecret) {
return errors.New("cannot use S3 config secret when restoring snapshot; configuration must be set in CLI or config file") return errors.New("cannot use S3 config secret when restoring snapshot; configuration must be set in CLI or config file")
} else { } else {
return errors.Wrap(err, "failed to initialize S3 client") return pkgerrors.WithMessage(err, "failed to initialize S3 client")
} }
} }
dir, err := snapshotDir(e.config, true) dir, err := snapshotDir(e.config, true)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get the snapshot dir") return pkgerrors.WithMessage(err, "failed to get the snapshot dir")
} }
path, err := s3client.Download(ctx, e.config.ClusterResetRestorePath, dir) path, err := s3client.Download(ctx, e.config.ClusterResetRestorePath, dir)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to download snapshot from S3") return pkgerrors.WithMessage(err, "failed to download snapshot from S3")
} }
e.config.ClusterResetRestorePath = path e.config.ClusterResetRestorePath = path
logrus.Infof("S3 download complete for %s", e.config.ClusterResetRestorePath) logrus.Infof("S3 download complete for %s", e.config.ClusterResetRestorePath)
...@@ -452,7 +453,7 @@ func (e *ETCD) Reset(ctx context.Context, rebootstrap func() error) error { ...@@ -452,7 +453,7 @@ func (e *ETCD) Reset(ctx context.Context, rebootstrap func() error) error {
func (e *ETCD) Start(ctx context.Context, clientAccessInfo *clientaccess.Info) error { func (e *ETCD) Start(ctx context.Context, clientAccessInfo *clientaccess.Info) error {
isInitialized, err := e.IsInitialized() isInitialized, err := e.IsInitialized()
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to check for initialized etcd datastore") return pkgerrors.WithMessagef(err, "failed to check for initialized etcd datastore")
} }
if err := e.startClient(ctx); err != nil { if err := e.startClient(ctx); err != nil {
...@@ -649,6 +650,13 @@ func (e *ETCD) Register(handler http.Handler) (http.Handler, error) { ...@@ -649,6 +650,13 @@ func (e *ETCD) Register(handler http.Handler) (http.Handler, error) {
// is being removed from the cluster. // is being removed from the cluster.
if !e.config.DisableAPIServer { if !e.config.DisableAPIServer {
e.config.Runtime.LeaderElectedClusterControllerStarts[version.Program+"-etcd"] = func(ctx context.Context) { e.config.Runtime.LeaderElectedClusterControllerStarts[version.Program+"-etcd"] = func(ctx context.Context) {
// ensure client is started, as etcd startup may not have handled this if this is a control-plane-only node
if e.client == nil {
if err := e.startClient(ctx); err != nil {
panic(pkgerrors.WithMessage(err, "failed to start etcd client"))
}
}
registerEndpointsHandlers(ctx, e) registerEndpointsHandlers(ctx, e)
registerMemberHandlers(ctx, e) registerMemberHandlers(ctx, e)
registerSnapshotHandlers(ctx, e) registerSnapshotHandlers(ctx, e)
...@@ -656,7 +664,7 @@ func (e *ETCD) Register(handler http.Handler) (http.Handler, error) { ...@@ -656,7 +664,7 @@ func (e *ETCD) Register(handler http.Handler) (http.Handler, error) {
// Re-run informer factory startup after core and leader-elected controllers have started. // Re-run informer factory startup after core and leader-elected controllers have started.
// Additional caches may need to start for the newly added OnChange/OnRemove callbacks. // Additional caches may need to start for the newly added OnChange/OnRemove callbacks.
if err := start.All(ctx, 5, e.config.Runtime.K3s, e.config.Runtime.Core); err != nil { if err := start.All(ctx, 5, e.config.Runtime.K3s, e.config.Runtime.Core); err != nil {
panic(errors.Wrap(err, "failed to start wrangler controllers")) panic(pkgerrors.WithMessage(err, "failed to start wrangler controllers"))
} }
} }
} }
...@@ -731,7 +739,7 @@ func (e *ETCD) infoHandler() http.Handler { ...@@ -731,7 +739,7 @@ func (e *ETCD) infoHandler() http.Handler {
members, err := e.client.MemberList(ctx) members, err := e.client.MemberList(ctx)
if err != nil { if err != nil {
util.SendError(errors.Wrap(err, "failed to get etcd MemberList"), rw, req, http.StatusInternalServerError) util.SendError(pkgerrors.WithMessage(err, "failed to get etcd MemberList"), rw, req, http.StatusInternalServerError)
return return
} }
...@@ -1314,7 +1322,7 @@ func (e *ETCD) trackLearnerProgress(ctx context.Context, progress *learnerProgre ...@@ -1314,7 +1322,7 @@ func (e *ETCD) trackLearnerProgress(ctx context.Context, progress *learnerProgre
func (e *ETCD) getETCDStatus(ctx context.Context, url string) (*clientv3.StatusResponse, error) { func (e *ETCD) getETCDStatus(ctx context.Context, url string) (*clientv3.StatusResponse, error) {
resp, err := e.client.Status(ctx, url) resp, err := e.client.Status(ctx, url)
if err != nil { if err != nil {
return resp, errors.Wrap(err, "failed to check etcd member status") return resp, pkgerrors.WithMessage(err, "failed to check etcd member status")
} }
if len(resp.Errors) != 0 { if len(resp.Errors) != 0 {
return resp, errors.New("etcd member has status errors: " + strings.Join(resp.Errors, ",")) return resp, errors.New("etcd member has status errors: " + strings.Join(resp.Errors, ","))
...@@ -1547,7 +1555,7 @@ func (e *ETCD) Restore(ctx context.Context) error { ...@@ -1547,7 +1555,7 @@ func (e *ETCD) Restore(ctx context.Context) error {
if strings.HasSuffix(e.config.ClusterResetRestorePath, snapshot.CompressedExtension) { if strings.HasSuffix(e.config.ClusterResetRestorePath, snapshot.CompressedExtension) {
dir, err := snapshotDir(e.config, true) dir, err := snapshotDir(e.config, true)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get the snapshot dir") return pkgerrors.WithMessage(err, "failed to get the snapshot dir")
} }
decompressSnapshot, err := e.decompressSnapshot(dir, e.config.ClusterResetRestorePath) decompressSnapshot, err := e.decompressSnapshot(dir, e.config.ClusterResetRestorePath)
...@@ -1648,6 +1656,12 @@ func GetAPIServerURLsFromETCD(ctx context.Context, cfg *config.Control) ([]strin ...@@ -1648,6 +1656,12 @@ func GetAPIServerURLsFromETCD(ctx context.Context, cfg *config.Control) ([]strin
// GetMembersClientURLs will list through the member lists in etcd and return // GetMembersClientURLs will list through the member lists in etcd and return
// back a combined list of client urls for each member in the cluster // back a combined list of client urls for each member in the cluster
func (e *ETCD) GetMembersClientURLs(ctx context.Context) ([]string, error) { func (e *ETCD) GetMembersClientURLs(ctx context.Context) ([]string, error) {
if e.client == nil {
if err := e.startClient(ctx); err != nil {
return nil, err
}
}
members, err := e.client.MemberList(ctx) members, err := e.client.MemberList(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -31,6 +31,7 @@ import ( ...@@ -31,6 +31,7 @@ import (
healthpb "google.golang.org/grpc/health/grpc_health_v1" healthpb "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilnet "k8s.io/apimachinery/pkg/util/net" utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
) )
...@@ -67,6 +68,7 @@ func generateTestConfig() *config.Control { ...@@ -67,6 +68,7 @@ func generateTestConfig() *config.Control {
DataDir: "/tmp/k3s/", // Different than the default value DataDir: "/tmp/k3s/", // Different than the default value
EtcdSnapshotName: "etcd-snapshot", EtcdSnapshotName: "etcd-snapshot",
EtcdSnapshotCron: "0 */12 * * *", EtcdSnapshotCron: "0 */12 * * *",
EtcdSnapshotReconcile: metav1.Duration{Duration: 10 * time.Minute},
EtcdSnapshotRetention: 5, EtcdSnapshotRetention: 5,
EtcdS3: &config.EtcdS3{ EtcdS3: &config.EtcdS3{
Endpoint: "s3.amazonaws.com", Endpoint: "s3.amazonaws.com",
......
...@@ -2,12 +2,12 @@ package etcd ...@@ -2,12 +2,12 @@ package etcd
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors"
controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes" "go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/base64" "encoding/base64"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
...@@ -26,7 +27,7 @@ import ( ...@@ -26,7 +27,7 @@ import (
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio-go/v7/pkg/credentials"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/rancher/wrangler/pkg/generated/controllers/core" "github.com/rancher/wrangler/pkg/generated/controllers/core"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
...@@ -99,13 +100,13 @@ func Start(ctx context.Context, config *config.Control) (*Controller, error) { ...@@ -99,13 +100,13 @@ func Start(ctx context.Context, config *config.Control) (*Controller, error) {
// cluster id hack: see https://groups.google.com/forum/#!msg/kubernetes-sig-architecture/mVGobfD4TpY/nkdbkX1iBwAJ // cluster id hack: see https://groups.google.com/forum/#!msg/kubernetes-sig-architecture/mVGobfD4TpY/nkdbkX1iBwAJ
ns, err := c.core.V1().Namespace().Get(metav1.NamespaceSystem, metav1.GetOptions{}) ns, err := c.core.V1().Namespace().Get(metav1.NamespaceSystem, metav1.GetOptions{})
if err != nil { if err != nil {
return false, errors.Wrap(err, "failed to set S3 snapshot cluster ID") return false, pkgerrors.WithMessage(err, "failed to set S3 snapshot cluster ID")
} }
c.clusterID = string(ns.UID) c.clusterID = string(ns.UID)
tokenHash, err := util.GetTokenHash(config) tokenHash, err := util.GetTokenHash(config)
if err != nil { if err != nil {
return false, errors.Wrap(err, "failed to set S3 snapshot server token hash") return false, pkgerrors.WithMessage(err, "failed to set S3 snapshot server token hash")
} }
c.tokenHash = tokenHash c.tokenHash = tokenHash
...@@ -137,7 +138,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli ...@@ -137,7 +138,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli
if isDefault { if isDefault {
e, err := c.getConfigFromSecret(etcdS3.ConfigSecret) e, err := c.getConfigFromSecret(etcdS3.ConfigSecret)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to get config from etcd-s3-config-secret %q", etcdS3.ConfigSecret) return nil, pkgerrors.WithMessagef(err, "failed to get config from etcd-s3-config-secret %q", etcdS3.ConfigSecret)
} }
logrus.Infof("Using etcd s3 configuration from etcd-s3-config-secret %q", etcdS3.ConfigSecret) logrus.Infof("Using etcd s3 configuration from etcd-s3-config-secret %q", etcdS3.ConfigSecret)
etcdS3 = e etcdS3 = e
...@@ -196,7 +197,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli ...@@ -196,7 +197,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli
if etcdS3.Proxy != "none" { if etcdS3.Proxy != "none" {
u, err = url.Parse(etcdS3.Proxy) u, err = url.Parse(etcdS3.Proxy)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to parse etcd-s3-proxy value as URL") return nil, pkgerrors.WithMessage(err, "failed to parse etcd-s3-proxy value as URL")
} }
if u.Scheme == "" || u.Host == "" { if u.Scheme == "" || u.Host == "" {
return nil, fmt.Errorf("proxy URL must include scheme and host") return nil, fmt.Errorf("proxy URL must include scheme and host")
...@@ -219,7 +220,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli ...@@ -219,7 +220,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli
}) })
if _, err := creds.Get(); err != nil { if _, err := creds.Get(); err != nil {
return nil, errors.Wrap(err, "failed to get credentials") return nil, pkgerrors.WithMessage(err, "failed to get credentials")
} }
opt := minio.Options{ opt := minio.Options{
...@@ -241,7 +242,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli ...@@ -241,7 +242,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli
exists, err := mc.BucketExists(ctx, etcdS3.Bucket) exists, err := mc.BucketExists(ctx, etcdS3.Bucket)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to test for existence of bucket %s", etcdS3.Bucket) return nil, pkgerrors.WithMessagef(err, "failed to test for existence of bucket %s", etcdS3.Bucket)
} }
if !exists { if !exists {
return nil, fmt.Errorf("bucket %s does not exist", etcdS3.Bucket) return nil, fmt.Errorf("bucket %s does not exist", etcdS3.Bucket)
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
"regexp" "regexp"
"strings" "strings"
k3s "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1" k3s "github.com/k3s-io/api/k3s.cattle.io/v1"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
......
...@@ -2,19 +2,20 @@ package etcd ...@@ -2,19 +2,20 @@ package etcd
import ( import (
"context" "context"
"errors"
"os" "os"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
apisv1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1" apisv1 "github.com/k3s-io/api/k3s.cattle.io/v1"
k3s "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1" k3s "github.com/k3s-io/api/k3s.cattle.io/v1"
controllersv1 "github.com/k3s-io/api/pkg/generated/controllers/k3s.cattle.io/v1"
"github.com/k3s-io/k3s/pkg/etcd/snapshot" "github.com/k3s-io/k3s/pkg/etcd/snapshot"
controllersv1 "github.com/k3s-io/k3s/pkg/generated/controllers/k3s.cattle.io/v1"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/equality"
...@@ -90,14 +91,14 @@ func (e *etcdSnapshotHandler) sync(key string, esf *apisv1.ETCDSnapshotFile) (*a ...@@ -90,14 +91,14 @@ func (e *etcdSnapshotHandler) sync(key string, esf *apisv1.ETCDSnapshotFile) (*a
sfKey := sf.GenerateConfigMapKey() sfKey := sf.GenerateConfigMapKey()
m, err := sf.Marshal() m, err := sf.Marshal()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to marshal snapshot ConfigMap data") return nil, pkgerrors.WithMessage(err, "failed to marshal snapshot ConfigMap data")
} }
marshalledSnapshot := string(m) marshalledSnapshot := string(m)
snapshotConfigMap, err := e.configmaps.Get(metav1.NamespaceSystem, snapshotConfigMapName, metav1.GetOptions{}) snapshotConfigMap, err := e.configmaps.Get(metav1.NamespaceSystem, snapshotConfigMapName, metav1.GetOptions{})
if err != nil { if err != nil {
if !apierrors.IsNotFound(err) { if !apierrors.IsNotFound(err) {
return nil, errors.Wrap(err, "failed to get snapshot ConfigMap") return nil, pkgerrors.WithMessage(err, "failed to get snapshot ConfigMap")
} }
snapshotConfigMap = &v1.ConfigMap{ snapshotConfigMap = &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
...@@ -142,7 +143,7 @@ func (e *etcdSnapshotHandler) sync(key string, esf *apisv1.ETCDSnapshotFile) (*a ...@@ -142,7 +143,7 @@ func (e *etcdSnapshotHandler) sync(key string, esf *apisv1.ETCDSnapshotFile) (*a
} }
if err != nil { if err != nil {
err = errors.Wrap(err, "failed to sync snapshot to ConfigMap") err = pkgerrors.WithMessage(err, "failed to sync snapshot to ConfigMap")
} }
return nil, err return nil, err
...@@ -157,14 +158,14 @@ func (e *etcdSnapshotHandler) onRemove(key string, esf *apisv1.ETCDSnapshotFile) ...@@ -157,14 +158,14 @@ func (e *etcdSnapshotHandler) onRemove(key string, esf *apisv1.ETCDSnapshotFile)
if apierrors.IsNotFound(err) { if apierrors.IsNotFound(err) {
return nil, nil return nil, nil
} }
return nil, errors.Wrap(err, "failed to get snapshot ConfigMap") return nil, pkgerrors.WithMessage(err, "failed to get snapshot ConfigMap")
} }
sfKey := generateETCDSnapshotFileConfigMapKey(*esf) sfKey := generateETCDSnapshotFileConfigMapKey(*esf)
if _, ok := snapshotConfigMap.Data[sfKey]; ok { if _, ok := snapshotConfigMap.Data[sfKey]; ok {
delete(snapshotConfigMap.Data, sfKey) delete(snapshotConfigMap.Data, sfKey)
if _, err := e.configmaps.Update(snapshotConfigMap); err != nil { if _, err := e.configmaps.Update(snapshotConfigMap); err != nil {
return nil, errors.Wrap(err, "failed to remove snapshot from ConfigMap") return nil, pkgerrors.WithMessage(err, "failed to remove snapshot from ConfigMap")
} }
} }
e.etcd.emitEvent(esf) e.etcd.emitEvent(esf)
...@@ -243,7 +244,7 @@ func (e *etcdSnapshotHandler) reconcile() error { ...@@ -243,7 +244,7 @@ func (e *etcdSnapshotHandler) reconcile() error {
snapshotConfigMap, err := e.configmaps.Get(metav1.NamespaceSystem, snapshotConfigMapName, metav1.GetOptions{}) snapshotConfigMap, err := e.configmaps.Get(metav1.NamespaceSystem, snapshotConfigMapName, metav1.GetOptions{})
if err != nil { if err != nil {
if !apierrors.IsNotFound(err) { if !apierrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get snapshot ConfigMap") return pkgerrors.WithMessage(err, "failed to get snapshot ConfigMap")
} }
snapshotConfigMap = &v1.ConfigMap{ snapshotConfigMap = &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
......
...@@ -7,11 +7,11 @@ import ( ...@@ -7,11 +7,11 @@ import (
"io" "io"
"net/http" "net/http"
k3s "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1" k3s "github.com/k3s-io/api/k3s.cattle.io/v1"
"github.com/k3s-io/k3s/pkg/cluster/managed" "github.com/k3s-io/k3s/pkg/cluster/managed"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/util" "github.com/k3s-io/k3s/pkg/util"
"github.com/pkg/errors" pkgerrors "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -70,7 +70,7 @@ func (e *ETCD) snapshotHandler() http.Handler { ...@@ -70,7 +70,7 @@ func (e *ETCD) snapshotHandler() http.Handler {
func (e *ETCD) handleList(rw http.ResponseWriter, req *http.Request) error { func (e *ETCD) handleList(rw http.ResponseWriter, req *http.Request) error {
if e.config.EtcdS3 != nil { if e.config.EtcdS3 != nil {
if _, err := e.getS3Client(req.Context()); err != nil { if _, err := e.getS3Client(req.Context()); err != nil {
err = errors.Wrap(err, "failed to initialize S3 client") err = pkgerrors.WithMessage(err, "failed to initialize S3 client")
util.SendError(err, rw, req, http.StatusBadRequest) util.SendError(err, rw, req, http.StatusBadRequest)
return nil return nil
} }
...@@ -87,7 +87,7 @@ func (e *ETCD) handleList(rw http.ResponseWriter, req *http.Request) error { ...@@ -87,7 +87,7 @@ func (e *ETCD) handleList(rw http.ResponseWriter, req *http.Request) error {
func (e *ETCD) handleSave(rw http.ResponseWriter, req *http.Request) error { func (e *ETCD) handleSave(rw http.ResponseWriter, req *http.Request) error {
if e.config.EtcdS3 != nil { if e.config.EtcdS3 != nil {
if _, err := e.getS3Client(req.Context()); err != nil { if _, err := e.getS3Client(req.Context()); err != nil {
err = errors.Wrap(err, "failed to initialize S3 client") err = pkgerrors.WithMessage(err, "failed to initialize S3 client")
util.SendError(err, rw, req, http.StatusBadRequest) util.SendError(err, rw, req, http.StatusBadRequest)
return nil return nil
} }
...@@ -104,7 +104,7 @@ func (e *ETCD) handleSave(rw http.ResponseWriter, req *http.Request) error { ...@@ -104,7 +104,7 @@ func (e *ETCD) handleSave(rw http.ResponseWriter, req *http.Request) error {
func (e *ETCD) handlePrune(rw http.ResponseWriter, req *http.Request) error { func (e *ETCD) handlePrune(rw http.ResponseWriter, req *http.Request) error {
if e.config.EtcdS3 != nil { if e.config.EtcdS3 != nil {
if _, err := e.getS3Client(req.Context()); err != nil { if _, err := e.getS3Client(req.Context()); err != nil {
err = errors.Wrap(err, "failed to initialize S3 client") err = pkgerrors.WithMessage(err, "failed to initialize S3 client")
util.SendError(err, rw, req, http.StatusBadRequest) util.SendError(err, rw, req, http.StatusBadRequest)
return nil return nil
} }
...@@ -121,7 +121,7 @@ func (e *ETCD) handlePrune(rw http.ResponseWriter, req *http.Request) error { ...@@ -121,7 +121,7 @@ func (e *ETCD) handlePrune(rw http.ResponseWriter, req *http.Request) error {
func (e *ETCD) handleDelete(rw http.ResponseWriter, req *http.Request, snapshots []string) error { func (e *ETCD) handleDelete(rw http.ResponseWriter, req *http.Request, snapshots []string) error {
if e.config.EtcdS3 != nil { if e.config.EtcdS3 != nil {
if _, err := e.getS3Client(req.Context()); err != nil { if _, err := e.getS3Client(req.Context()); err != nil {
err = errors.Wrap(err, "failed to initialize S3 client") err = pkgerrors.WithMessage(err, "failed to initialize S3 client")
util.SendError(err, rw, req, http.StatusBadRequest) util.SendError(err, rw, req, http.StatusBadRequest)
return nil return nil
} }
......
package etcd
import (
"github.com/k3s-io/k3s/pkg/version"
"github.com/prometheus/client_golang/prometheus"
"k8s.io/component-base/metrics"
)
var (
snapshotSaveCount = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: version.Program + "_etcd_snapshot_save_duration_seconds",
Help: "Total time taken to complete the etcd snapshot process",
Buckets: metrics.ExponentialBuckets(0.008, 2, 15),
}, []string{"status"})
snapshotSaveLocalCount = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: version.Program + "_etcd_snapshot_save_local_duration_seconds",
Help: "Total time taken to save a local snapshot file",
Buckets: metrics.ExponentialBuckets(0.008, 2, 15),
}, []string{"status"})
snapshotSaveS3Count = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: version.Program + "_etcd_snapshot_save_s3_duration_seconds",
Help: "Total time taken to upload a snapshot file to S3",
Buckets: metrics.ExponentialBuckets(0.008, 2, 15),
}, []string{"status"})
snapshotReconcileCount = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: version.Program + "_etcd_snapshot_reconcile_duration_seconds",
Help: "Total time taken to sync the list of etcd snapshots",
Buckets: metrics.ExponentialBuckets(0.008, 2, 15),
}, []string{"status"})
snapshotReconcileLocalCount = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: version.Program + "_etcd_snapshot_reconcile_local_duration_seconds",
Help: "Total time taken to list local snapshot files",
Buckets: metrics.ExponentialBuckets(0.008, 2, 15),
}, []string{"status"})
snapshotReconcileS3Count = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: version.Program + "_etcd_snapshot_reconcile_s3_duration_seconds",
Help: "Total time taken to list S3 snapshot files",
Buckets: metrics.ExponentialBuckets(0.008, 2, 15),
}, []string{"status"})
)
// MustRegister registers etcd snapshot metrics
func MustRegister(registerer prometheus.Registerer) {
registerer.MustRegister(
snapshotSaveCount,
snapshotSaveLocalCount,
snapshotSaveS3Count,
snapshotReconcileCount,
snapshotReconcileLocalCount,
snapshotReconcileS3Count,
)
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package versioned
import (
"fmt"
"net/http"
k3sv1 "github.com/k3s-io/k3s/pkg/generated/clientset/versioned/typed/k3s.cattle.io/v1"
discovery "k8s.io/client-go/discovery"
rest "k8s.io/client-go/rest"
flowcontrol "k8s.io/client-go/util/flowcontrol"
)
type Interface interface {
Discovery() discovery.DiscoveryInterface
K3sV1() k3sv1.K3sV1Interface
}
// Clientset contains the clients for groups.
type Clientset struct {
*discovery.DiscoveryClient
k3sV1 *k3sv1.K3sV1Client
}
// K3sV1 retrieves the K3sV1Client
func (c *Clientset) K3sV1() k3sv1.K3sV1Interface {
return c.k3sV1
}
// Discovery retrieves the DiscoveryClient
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
if c == nil {
return nil
}
return c.DiscoveryClient
}
// NewForConfig creates a new Clientset for the given config.
// If config's RateLimiter is not set and QPS and Burst are acceptable,
// NewForConfig will generate a rate-limiter in configShallowCopy.
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(c *rest.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.UserAgent == "" {
configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent()
}
// share the transport between all clients
httpClient, err := rest.HTTPClientFor(&configShallowCopy)
if err != nil {
return nil, err
}
return NewForConfigAndClient(&configShallowCopy, httpClient)
}
// NewForConfigAndClient creates a new Clientset for the given config and http client.
// Note the http client provided takes precedence over the configured transport values.
// If config's RateLimiter is not set and QPS and Burst are acceptable,
// NewForConfigAndClient will generate a rate-limiter in configShallowCopy.
func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
if configShallowCopy.Burst <= 0 {
return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
}
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var cs Clientset
var err error
cs.k3sV1, err = k3sv1.NewForConfigAndClient(&configShallowCopy, httpClient)
if err != nil {
return nil, err
}
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient)
if err != nil {
return nil, err
}
return &cs, nil
}
// NewForConfigOrDie creates a new Clientset for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *Clientset {
cs, err := NewForConfig(c)
if err != nil {
panic(err)
}
return cs
}
// New creates a new Clientset for the given RESTClient.
func New(c rest.Interface) *Clientset {
var cs Clientset
cs.k3sV1 = k3sv1.New(c)
cs.DiscoveryClient = discovery.NewDiscoveryClient(c)
return &cs
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package fake
import (
clientset "github.com/k3s-io/k3s/pkg/generated/clientset/versioned"
k3sv1 "github.com/k3s-io/k3s/pkg/generated/clientset/versioned/typed/k3s.cattle.io/v1"
fakek3sv1 "github.com/k3s-io/k3s/pkg/generated/clientset/versioned/typed/k3s.cattle.io/v1/fake"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/discovery"
fakediscovery "k8s.io/client-go/discovery/fake"
"k8s.io/client-go/testing"
)
// NewSimpleClientset returns a clientset that will respond with the provided objects.
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
// without applying any validations and/or defaults. It shouldn't be considered a replacement
// for a real clientset and is mostly useful in simple unit tests.
func NewSimpleClientset(objects ...runtime.Object) *Clientset {
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
for _, obj := range objects {
if err := o.Add(obj); err != nil {
panic(err)
}
}
cs := &Clientset{tracker: o}
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
cs.AddReactor("*", "*", testing.ObjectReaction(o))
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
gvr := action.GetResource()
ns := action.GetNamespace()
watch, err := o.Watch(gvr, ns)
if err != nil {
return false, nil, err
}
return true, watch, nil
})
return cs
}
// Clientset implements clientset.Interface. Meant to be embedded into a
// struct to get a default implementation. This makes faking out just the method
// you want to test easier.
type Clientset struct {
testing.Fake
discovery *fakediscovery.FakeDiscovery
tracker testing.ObjectTracker
}
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
return c.discovery
}
func (c *Clientset) Tracker() testing.ObjectTracker {
return c.tracker
}
var (
_ clientset.Interface = &Clientset{}
_ testing.FakeClient = &Clientset{}
)
// K3sV1 retrieves the K3sV1Client
func (c *Clientset) K3sV1() k3sv1.K3sV1Interface {
return &fakek3sv1.FakeK3sV1{Fake: &c.Fake}
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
// This package has the automatically generated fake clientset.
package fake
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package fake
import (
k3sv1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)
var scheme = runtime.NewScheme()
var codecs = serializer.NewCodecFactory(scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
k3sv1.AddToScheme,
}
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
var AddToScheme = localSchemeBuilder.AddToScheme
func init() {
v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"})
utilruntime.Must(AddToScheme(scheme))
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
// This package contains the scheme of the automatically generated clientset.
package scheme
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package scheme
import (
k3sv1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)
var Scheme = runtime.NewScheme()
var Codecs = serializer.NewCodecFactory(Scheme)
var ParameterCodec = runtime.NewParameterCodec(Scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
k3sv1.AddToScheme,
}
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
var AddToScheme = localSchemeBuilder.AddToScheme
func init() {
v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
utilruntime.Must(AddToScheme(Scheme))
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"context"
"time"
v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
scheme "github.com/k3s-io/k3s/pkg/generated/clientset/versioned/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
)
// AddonsGetter has a method to return a AddonInterface.
// A group's client should implement this interface.
type AddonsGetter interface {
Addons(namespace string) AddonInterface
}
// AddonInterface has methods to work with Addon resources.
type AddonInterface interface {
Create(ctx context.Context, addon *v1.Addon, opts metav1.CreateOptions) (*v1.Addon, error)
Update(ctx context.Context, addon *v1.Addon, opts metav1.UpdateOptions) (*v1.Addon, error)
Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error
Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Addon, error)
List(ctx context.Context, opts metav1.ListOptions) (*v1.AddonList, error)
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Addon, err error)
AddonExpansion
}
// addons implements AddonInterface
type addons struct {
client rest.Interface
ns string
}
// newAddons returns a Addons
func newAddons(c *K3sV1Client, namespace string) *addons {
return &addons{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the addon, and returns the corresponding addon object, and an error if there is any.
func (c *addons) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Addon, err error) {
result = &v1.Addon{}
err = c.client.Get().
Namespace(c.ns).
Resource("addons").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of Addons that match those selectors.
func (c *addons) List(ctx context.Context, opts metav1.ListOptions) (result *v1.AddonList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1.AddonList{}
err = c.client.Get().
Namespace(c.ns).
Resource("addons").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested addons.
func (c *addons) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("addons").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a addon and creates it. Returns the server's representation of the addon, and an error, if there is any.
func (c *addons) Create(ctx context.Context, addon *v1.Addon, opts metav1.CreateOptions) (result *v1.Addon, err error) {
result = &v1.Addon{}
err = c.client.Post().
Namespace(c.ns).
Resource("addons").
VersionedParams(&opts, scheme.ParameterCodec).
Body(addon).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a addon and updates it. Returns the server's representation of the addon, and an error, if there is any.
func (c *addons) Update(ctx context.Context, addon *v1.Addon, opts metav1.UpdateOptions) (result *v1.Addon, err error) {
result = &v1.Addon{}
err = c.client.Put().
Namespace(c.ns).
Resource("addons").
Name(addon.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(addon).
Do(ctx).
Into(result)
return
}
// Delete takes name of the addon and deletes it. Returns an error if one occurs.
func (c *addons) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("addons").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *addons) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
var timeout time.Duration
if listOpts.TimeoutSeconds != nil {
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
}
return c.client.Delete().
Namespace(c.ns).
Resource("addons").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched addon.
func (c *addons) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Addon, err error) {
result = &v1.Addon{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("addons").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
// This package has the automatically generated typed clients.
package v1
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"context"
"time"
v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
scheme "github.com/k3s-io/k3s/pkg/generated/clientset/versioned/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
)
// ETCDSnapshotFilesGetter has a method to return a ETCDSnapshotFileInterface.
// A group's client should implement this interface.
type ETCDSnapshotFilesGetter interface {
ETCDSnapshotFiles() ETCDSnapshotFileInterface
}
// ETCDSnapshotFileInterface has methods to work with ETCDSnapshotFile resources.
type ETCDSnapshotFileInterface interface {
Create(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.CreateOptions) (*v1.ETCDSnapshotFile, error)
Update(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (*v1.ETCDSnapshotFile, error)
UpdateStatus(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (*v1.ETCDSnapshotFile, error)
Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error
Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.ETCDSnapshotFile, error)
List(ctx context.Context, opts metav1.ListOptions) (*v1.ETCDSnapshotFileList, error)
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ETCDSnapshotFile, err error)
ETCDSnapshotFileExpansion
}
// eTCDSnapshotFiles implements ETCDSnapshotFileInterface
type eTCDSnapshotFiles struct {
client rest.Interface
}
// newETCDSnapshotFiles returns a ETCDSnapshotFiles
func newETCDSnapshotFiles(c *K3sV1Client) *eTCDSnapshotFiles {
return &eTCDSnapshotFiles{
client: c.RESTClient(),
}
}
// Get takes name of the eTCDSnapshotFile, and returns the corresponding eTCDSnapshotFile object, and an error if there is any.
func (c *eTCDSnapshotFiles) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ETCDSnapshotFile, err error) {
result = &v1.ETCDSnapshotFile{}
err = c.client.Get().
Resource("etcdsnapshotfiles").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of ETCDSnapshotFiles that match those selectors.
func (c *eTCDSnapshotFiles) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ETCDSnapshotFileList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1.ETCDSnapshotFileList{}
err = c.client.Get().
Resource("etcdsnapshotfiles").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested eTCDSnapshotFiles.
func (c *eTCDSnapshotFiles) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Resource("etcdsnapshotfiles").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a eTCDSnapshotFile and creates it. Returns the server's representation of the eTCDSnapshotFile, and an error, if there is any.
func (c *eTCDSnapshotFiles) Create(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.CreateOptions) (result *v1.ETCDSnapshotFile, err error) {
result = &v1.ETCDSnapshotFile{}
err = c.client.Post().
Resource("etcdsnapshotfiles").
VersionedParams(&opts, scheme.ParameterCodec).
Body(eTCDSnapshotFile).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a eTCDSnapshotFile and updates it. Returns the server's representation of the eTCDSnapshotFile, and an error, if there is any.
func (c *eTCDSnapshotFiles) Update(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (result *v1.ETCDSnapshotFile, err error) {
result = &v1.ETCDSnapshotFile{}
err = c.client.Put().
Resource("etcdsnapshotfiles").
Name(eTCDSnapshotFile.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(eTCDSnapshotFile).
Do(ctx).
Into(result)
return
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *eTCDSnapshotFiles) UpdateStatus(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (result *v1.ETCDSnapshotFile, err error) {
result = &v1.ETCDSnapshotFile{}
err = c.client.Put().
Resource("etcdsnapshotfiles").
Name(eTCDSnapshotFile.Name).
SubResource("status").
VersionedParams(&opts, scheme.ParameterCodec).
Body(eTCDSnapshotFile).
Do(ctx).
Into(result)
return
}
// Delete takes name of the eTCDSnapshotFile and deletes it. Returns an error if one occurs.
func (c *eTCDSnapshotFiles) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return c.client.Delete().
Resource("etcdsnapshotfiles").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *eTCDSnapshotFiles) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
var timeout time.Duration
if listOpts.TimeoutSeconds != nil {
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
}
return c.client.Delete().
Resource("etcdsnapshotfiles").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched eTCDSnapshotFile.
func (c *eTCDSnapshotFiles) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ETCDSnapshotFile, err error) {
result = &v1.ETCDSnapshotFile{}
err = c.client.Patch(pt).
Resource("etcdsnapshotfiles").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
// Package fake has the automatically generated clients.
package fake
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package fake
import (
"context"
v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
labels "k8s.io/apimachinery/pkg/labels"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
testing "k8s.io/client-go/testing"
)
// FakeAddons implements AddonInterface
type FakeAddons struct {
Fake *FakeK3sV1
ns string
}
var addonsResource = v1.SchemeGroupVersion.WithResource("addons")
var addonsKind = v1.SchemeGroupVersion.WithKind("Addon")
// Get takes name of the addon, and returns the corresponding addon object, and an error if there is any.
func (c *FakeAddons) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Addon, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(addonsResource, c.ns, name), &v1.Addon{})
if obj == nil {
return nil, err
}
return obj.(*v1.Addon), err
}
// List takes label and field selectors, and returns the list of Addons that match those selectors.
func (c *FakeAddons) List(ctx context.Context, opts metav1.ListOptions) (result *v1.AddonList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(addonsResource, addonsKind, c.ns, opts), &v1.AddonList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1.AddonList{ListMeta: obj.(*v1.AddonList).ListMeta}
for _, item := range obj.(*v1.AddonList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
// Watch returns a watch.Interface that watches the requested addons.
func (c *FakeAddons) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(addonsResource, c.ns, opts))
}
// Create takes the representation of a addon and creates it. Returns the server's representation of the addon, and an error, if there is any.
func (c *FakeAddons) Create(ctx context.Context, addon *v1.Addon, opts metav1.CreateOptions) (result *v1.Addon, err error) {
obj, err := c.Fake.
Invokes(testing.NewCreateAction(addonsResource, c.ns, addon), &v1.Addon{})
if obj == nil {
return nil, err
}
return obj.(*v1.Addon), err
}
// Update takes the representation of a addon and updates it. Returns the server's representation of the addon, and an error, if there is any.
func (c *FakeAddons) Update(ctx context.Context, addon *v1.Addon, opts metav1.UpdateOptions) (result *v1.Addon, err error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateAction(addonsResource, c.ns, addon), &v1.Addon{})
if obj == nil {
return nil, err
}
return obj.(*v1.Addon), err
}
// Delete takes name of the addon and deletes it. Returns an error if one occurs.
func (c *FakeAddons) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteActionWithOptions(addonsResource, c.ns, name, opts), &v1.Addon{})
return err
}
// DeleteCollection deletes a collection of objects.
func (c *FakeAddons) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
action := testing.NewDeleteCollectionAction(addonsResource, c.ns, listOpts)
_, err := c.Fake.Invokes(action, &v1.AddonList{})
return err
}
// Patch applies the patch and returns the patched addon.
func (c *FakeAddons) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Addon, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(addonsResource, c.ns, name, pt, data, subresources...), &v1.Addon{})
if obj == nil {
return nil, err
}
return obj.(*v1.Addon), err
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package fake
import (
"context"
v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
labels "k8s.io/apimachinery/pkg/labels"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
testing "k8s.io/client-go/testing"
)
// FakeETCDSnapshotFiles implements ETCDSnapshotFileInterface
type FakeETCDSnapshotFiles struct {
Fake *FakeK3sV1
}
var etcdsnapshotfilesResource = v1.SchemeGroupVersion.WithResource("etcdsnapshotfiles")
var etcdsnapshotfilesKind = v1.SchemeGroupVersion.WithKind("ETCDSnapshotFile")
// Get takes name of the eTCDSnapshotFile, and returns the corresponding eTCDSnapshotFile object, and an error if there is any.
func (c *FakeETCDSnapshotFiles) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ETCDSnapshotFile, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootGetAction(etcdsnapshotfilesResource, name), &v1.ETCDSnapshotFile{})
if obj == nil {
return nil, err
}
return obj.(*v1.ETCDSnapshotFile), err
}
// List takes label and field selectors, and returns the list of ETCDSnapshotFiles that match those selectors.
func (c *FakeETCDSnapshotFiles) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ETCDSnapshotFileList, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootListAction(etcdsnapshotfilesResource, etcdsnapshotfilesKind, opts), &v1.ETCDSnapshotFileList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1.ETCDSnapshotFileList{ListMeta: obj.(*v1.ETCDSnapshotFileList).ListMeta}
for _, item := range obj.(*v1.ETCDSnapshotFileList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
// Watch returns a watch.Interface that watches the requested eTCDSnapshotFiles.
func (c *FakeETCDSnapshotFiles) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewRootWatchAction(etcdsnapshotfilesResource, opts))
}
// Create takes the representation of a eTCDSnapshotFile and creates it. Returns the server's representation of the eTCDSnapshotFile, and an error, if there is any.
func (c *FakeETCDSnapshotFiles) Create(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.CreateOptions) (result *v1.ETCDSnapshotFile, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootCreateAction(etcdsnapshotfilesResource, eTCDSnapshotFile), &v1.ETCDSnapshotFile{})
if obj == nil {
return nil, err
}
return obj.(*v1.ETCDSnapshotFile), err
}
// Update takes the representation of a eTCDSnapshotFile and updates it. Returns the server's representation of the eTCDSnapshotFile, and an error, if there is any.
func (c *FakeETCDSnapshotFiles) Update(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (result *v1.ETCDSnapshotFile, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootUpdateAction(etcdsnapshotfilesResource, eTCDSnapshotFile), &v1.ETCDSnapshotFile{})
if obj == nil {
return nil, err
}
return obj.(*v1.ETCDSnapshotFile), err
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *FakeETCDSnapshotFiles) UpdateStatus(ctx context.Context, eTCDSnapshotFile *v1.ETCDSnapshotFile, opts metav1.UpdateOptions) (*v1.ETCDSnapshotFile, error) {
obj, err := c.Fake.
Invokes(testing.NewRootUpdateSubresourceAction(etcdsnapshotfilesResource, "status", eTCDSnapshotFile), &v1.ETCDSnapshotFile{})
if obj == nil {
return nil, err
}
return obj.(*v1.ETCDSnapshotFile), err
}
// Delete takes name of the eTCDSnapshotFile and deletes it. Returns an error if one occurs.
func (c *FakeETCDSnapshotFiles) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewRootDeleteActionWithOptions(etcdsnapshotfilesResource, name, opts), &v1.ETCDSnapshotFile{})
return err
}
// DeleteCollection deletes a collection of objects.
func (c *FakeETCDSnapshotFiles) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
action := testing.NewRootDeleteCollectionAction(etcdsnapshotfilesResource, listOpts)
_, err := c.Fake.Invokes(action, &v1.ETCDSnapshotFileList{})
return err
}
// Patch applies the patch and returns the patched eTCDSnapshotFile.
func (c *FakeETCDSnapshotFiles) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ETCDSnapshotFile, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootPatchSubresourceAction(etcdsnapshotfilesResource, name, pt, data, subresources...), &v1.ETCDSnapshotFile{})
if obj == nil {
return nil, err
}
return obj.(*v1.ETCDSnapshotFile), err
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package fake
import (
v1 "github.com/k3s-io/k3s/pkg/generated/clientset/versioned/typed/k3s.cattle.io/v1"
rest "k8s.io/client-go/rest"
testing "k8s.io/client-go/testing"
)
type FakeK3sV1 struct {
*testing.Fake
}
func (c *FakeK3sV1) Addons(namespace string) v1.AddonInterface {
return &FakeAddons{c, namespace}
}
func (c *FakeK3sV1) ETCDSnapshotFiles() v1.ETCDSnapshotFileInterface {
return &FakeETCDSnapshotFiles{c}
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *FakeK3sV1) RESTClient() rest.Interface {
var ret *rest.RESTClient
return ret
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
type AddonExpansion interface{}
type ETCDSnapshotFileExpansion interface{}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"net/http"
v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
"github.com/k3s-io/k3s/pkg/generated/clientset/versioned/scheme"
rest "k8s.io/client-go/rest"
)
type K3sV1Interface interface {
RESTClient() rest.Interface
AddonsGetter
ETCDSnapshotFilesGetter
}
// K3sV1Client is used to interact with features provided by the k3s.cattle.io group.
type K3sV1Client struct {
restClient rest.Interface
}
func (c *K3sV1Client) Addons(namespace string) AddonInterface {
return newAddons(c, namespace)
}
func (c *K3sV1Client) ETCDSnapshotFiles() ETCDSnapshotFileInterface {
return newETCDSnapshotFiles(c)
}
// NewForConfig creates a new K3sV1Client for the given config.
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(c *rest.Config) (*K3sV1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
httpClient, err := rest.HTTPClientFor(&config)
if err != nil {
return nil, err
}
return NewForConfigAndClient(&config, httpClient)
}
// NewForConfigAndClient creates a new K3sV1Client for the given config and http client.
// Note the http client provided takes precedence over the configured transport values.
func NewForConfigAndClient(c *rest.Config, h *http.Client) (*K3sV1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
client, err := rest.RESTClientForConfigAndClient(&config, h)
if err != nil {
return nil, err
}
return &K3sV1Client{client}, nil
}
// NewForConfigOrDie creates a new K3sV1Client for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *K3sV1Client {
client, err := NewForConfig(c)
if err != nil {
panic(err)
}
return client
}
// New creates a new K3sV1Client for the given RESTClient.
func New(c rest.Interface) *K3sV1Client {
return &K3sV1Client{c}
}
func setConfigDefaults(config *rest.Config) error {
gv := v1.SchemeGroupVersion
config.GroupVersion = &gv
config.APIPath = "/apis"
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
if config.UserAgent == "" {
config.UserAgent = rest.DefaultKubernetesUserAgent()
}
return nil
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *K3sV1Client) RESTClient() rest.Interface {
if c == nil {
return nil
}
return c.restClient
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package k3s
import (
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) K3s() Interface {
return New(c.ControllerFactory())
}
func (c *Factory) WithAgent(userAgent string) Interface {
return New(controller.NewSharedControllerFactoryWithAgent(userAgent, c.ControllerFactory()))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment