Skip to content

Commit

Permalink
Merge pull request #909 from ncopa/kube-1.21.1
Browse files Browse the repository at this point in the history
Kube 1.21.1 cherry-picks for release-1.21
  • Loading branch information
ncopa committed May 20, 2021
2 parents 8996c28 + 57353ac commit c80fabd
Show file tree
Hide file tree
Showing 35 changed files with 963 additions and 278 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,9 @@ jobs:
env:
EMBEDDED_BINS_BUILDMODE: none

- name: go modules check
run: make lint-gomod

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
Expand Down
44 changes: 39 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ ifeq ($(DEBUG), false)
LD_FLAGS ?= -w -s
endif

KUBECTL_VERSION = $(shell go mod graph | grep "github.com/k0sproject/k0s" | grep kubectl | cut -d "@" -f 2 | sed "s/v0\./1./")
KUBECTL_MAJOR= $(shell echo ${KUBECTL_VERSION} | cut -d "." -f 1)
KUBECTL_MINOR= $(shell echo ${KUBECTL_VERSION} | cut -d "." -f 2)
BUILD_DATE = $(shell date ${SOURCE_DATE_EPOCH:+"--date=@${SOURCE_DATE_EPOCH:-}"} -u +'%Y-%m-%dT%H:%M:%SZ')

LD_FLAGS += -X github.com/k0sproject/k0s/pkg/build.Version=$(VERSION)
LD_FLAGS += -X github.com/k0sproject/k0s/pkg/build.RuncVersion=$(runc_version)
LD_FLAGS += -X github.com/k0sproject/k0s/pkg/build.ContainerdVersion=$(containerd_version)
Expand All @@ -30,15 +35,21 @@ LD_FLAGS += -X github.com/k0sproject/k0s/pkg/build.EtcdVersion=$(etcd_version)
LD_FLAGS += -X github.com/k0sproject/k0s/pkg/build.KonnectivityVersion=$(konnectivity_version)
LD_FLAGS += -X \"github.com/k0sproject/k0s/pkg/build.EulaNotice=$(EULA_NOTICE)\"
LD_FLAGS += -X github.com/k0sproject/k0s/pkg/telemetry.segmentToken=$(SEGMENT_TOKEN)
LD_FLAGS += -X k8s.io/component-base/version.gitVersion="v$(KUBECTL_VERSION)"
LD_FLAGS += -X k8s.io/component-base/version.gitMajor="$(KUBECTL_MAJOR)"
LD_FLAGS += -X k8s.io/component-base/version.gitMinor="$(KUBECTL_MINOR)"
LD_FLAGS += -X k8s.io/component-base/version.buildDate=$(BUILD_DATE)
LD_FLAGS += -X k8s.io/component-base/version.gitCommit="not_available"


golint := $(shell which golangci-lint)
ifeq ($(golint),)
golint := go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0 && "${GOPATH}/bin/golangci-lint"
golint := cd hack/ci-deps && go install github.com/golangci/golangci-lint/cmd/golangci-lint && cd ../.. && "${GOPATH}/bin/golangci-lint"
endif

go_bindata := $(shell which go-bindata)
ifeq ($(go_bindata),)
go_bindata := go get github.com/kevinburke/go-bindata/...@v3.22.0 && "${GOPATH}/bin/go-bindata"
go_bindata := cd hack/ci-deps && go install github.com/kevinburke/go-bindata/... && cd ../.. && "${GOPATH}/bin/go-bindata"
endif

GOLANG_IMAGE = golang:1.16-alpine
Expand Down Expand Up @@ -73,8 +84,8 @@ pkg/assets/zz_generated_offsets_linux.go pkg/assets/zz_generated_offsets_windows
else
pkg/assets/zz_generated_offsets_linux.go: .bins.linux.stamp
pkg/assets/zz_generated_offsets_windows.go: .bins.windows.stamp
pkg/assets/zz_generated_offsets_linux.go pkg/assets/zz_generated_offsets_windows.go: gen_bindata.go
GOOS=${GOHOSTOS} $(GO) run gen_bindata.go -o bindata_$(zz_os) -pkg assets \
pkg/assets/zz_generated_offsets_linux.go pkg/assets/zz_generated_offsets_windows.go:
GOOS=${GOHOSTOS} $(GO) run hack/gen-bindata/main.go -o bindata_$(zz_os) -pkg assets \
-gofile pkg/assets/zz_generated_offsets_$(zz_os).go \
-prefix embedded-bins/staging/$(zz_os)/ embedded-bins/staging/$(zz_os)/bin
endif
Expand All @@ -98,8 +109,13 @@ k0s.exe k0s: $(GO_SRCS)
$(MAKE) -C embedded-bins buildmode=$(EMBEDDED_BINS_BUILDMODE) TARGET_OS=$(patsubst .bins.%.stamp,%,$@)
touch $@

SKIP_GOMOD_LINT ?= false
ifeq ($(SKIP_GOMOD_LINT), false)
GOMODLINT=lint-gomod
endif

.PHONY: lint
lint: pkg/assets/zz_generated_offsets_$(TARGET_OS).go
lint: pkg/assets/zz_generated_offsets_$(TARGET_OS).go ${GOMODLINT}
$(golint) run ./...

.PHONY: $(smoketests)
Expand All @@ -120,6 +136,7 @@ clean:
rm -f pkg/assets/zz_generated_offsets_*.go k0s k0s.exe .bins.*stamp bindata* static/gen_manifests.go
$(MAKE) -C embedded-bins clean
$(MAKE) -C image-bundle clean
$(MAKE) -C inttest clean

.PHONY: manifests
manifests:
Expand All @@ -136,3 +153,20 @@ image-bundle/image.list: k0s

image-bundle/bundle.tar: image-bundle/image.list
$(MAKE) -C image-bundle bundle.tar


GOMODTIDYLINT=sh -c '\
if [ `git diff go.mod go.sum | wc -l` -gt "0" ]; then \
echo "Run \`go mod tidy\` and commit the result"; \
exit 1; \
fi ; \
${GO} mod tidy; \
if [ `git diff go.mod go.sum | wc -l` -gt "0" ]; then \
git checkout go.mod go.sum ; \
echo "Linter failure: go.mod and go.sum have unused deps. Run \`go mod tidy\` and commit the result"; \
exit 2; \
fi \
; ' GOMODTIDYLINT
lint-gomod:
@${GOMODTIDYLINT}
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import (
"github.com/k0sproject/k0s/cmd/kubectl"
"github.com/k0sproject/k0s/cmd/reset"
"github.com/k0sproject/k0s/cmd/restore"
"github.com/k0sproject/k0s/cmd/start"
"github.com/k0sproject/k0s/cmd/status"
"github.com/k0sproject/k0s/cmd/stop"
"github.com/k0sproject/k0s/cmd/token"
"github.com/k0sproject/k0s/cmd/validate"
"github.com/k0sproject/k0s/cmd/version"
Expand Down Expand Up @@ -81,6 +83,8 @@ func NewRootCmd() *cobra.Command {
cmd.AddCommand(kubectl.NewK0sKubectlCmd())
cmd.AddCommand(reset.NewResetCmd())
cmd.AddCommand(status.NewStatusCmd())
cmd.AddCommand(start.NewStartCmd())
cmd.AddCommand(stop.NewStopCmd())
cmd.AddCommand(token.NewTokenCmd())
cmd.AddCommand(validate.NewValidateCmd())
cmd.AddCommand(version.NewVersionCmd())
Expand Down
48 changes: 48 additions & 0 deletions cmd/start/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2021 k0s 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.
*/
package start

import (
"fmt"
"os"

"github.com/k0sproject/k0s/pkg/install"
"github.com/kardianos/service"
"github.com/spf13/cobra"
)

func NewStartCmd() *cobra.Command {
return &cobra.Command{
Use: "start",
Short: "Start the k0s service configured on this host. Must be run as root (or with sudo)",
RunE: func(cmd *cobra.Command, args []string) error {
if os.Geteuid() != 0 {
return fmt.Errorf("this command must be run as root")
}
svc, err := install.InstalledService()
if err != nil {
return err
}
status, _ := svc.Status()
if status == service.StatusRunning {
cmd.SilenceUsage = true
return fmt.Errorf("already running")
}
return svc.Start()
},
}

}
51 changes: 51 additions & 0 deletions cmd/stop/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2021 k0s 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.
*/
package stop

import (
"fmt"
"os"

"github.com/k0sproject/k0s/pkg/install"
"github.com/kardianos/service"
"github.com/spf13/cobra"
)

func NewStopCmd() *cobra.Command {
return &cobra.Command{
Use: "stop",
Short: "Stop the k0s service configured on this host. Must be run as root (or with sudo)",
RunE: func(cmd *cobra.Command, args []string) error {
if os.Geteuid() != 0 {
return fmt.Errorf("this command must be run as root")
}
svc, err := install.InstalledService()
if err != nil {
return err
}
status, err := svc.Status()
if err != nil {
return err
}
if status == service.StatusStopped {
cmd.SilenceUsage = true
return fmt.Errorf("already stopped")
}
return svc.Stop()
},
}

}
11 changes: 7 additions & 4 deletions cmd/token/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/k0sproject/k0s/pkg/token"
)

var createTokenRole string

func tokenCreateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Expand Down Expand Up @@ -58,7 +60,7 @@ k0s token create --role worker --expiry 10m //sets expiration time to 10 minute
}, func(err error) bool {
return waitCreate
}, func() error {
bootstrapConfig, err = token.CreateKubeletBootstrapConfig(clusterConfig, c.K0sVars, tokenRole, expiry)
bootstrapConfig, err = token.CreateKubeletBootstrapConfig(clusterConfig, c.K0sVars, createTokenRole, expiry)

return err
})
Expand All @@ -71,11 +73,12 @@ k0s token create --role worker --expiry 10m //sets expiration time to 10 minute
return nil
},
}
// append flags
cmd.PersistentFlags().AddFlagSet(config.GetPersistentFlagSet())

cmd.Flags().StringVar(&tokenExpiry, "expiry", "0s", "Expiration time of the token. Format 1.5h, 2h45m or 300ms.")
cmd.Flags().StringVar(&tokenRole, "role", "worker", "Either worker or controller")
cmd.Flags().StringVar(&createTokenRole, "role", "worker", "Either worker or controller")
cmd.Flags().BoolVar(&waitCreate, "wait", false, "wait forever (default false)")

// append flags
cmd.PersistentFlags().AddFlagSet(config.GetPersistentFlagSet())
return cmd
}
6 changes: 4 additions & 2 deletions cmd/token/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/spf13/cobra"
)

var listTokenRole string

func tokenListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Expand All @@ -38,7 +40,7 @@ func tokenListCmd() *cobra.Command {
return err
}

tokens, err := manager.List(tokenRole)
tokens, err := manager.List(listTokenRole)
if err != nil {
return err
}
Expand Down Expand Up @@ -70,7 +72,7 @@ func tokenListCmd() *cobra.Command {
return nil
},
}
cmd.Flags().StringVar(&tokenRole, "role", "", "Either worker, controller or empty for all roles")
cmd.Flags().StringVar(&listTokenRole, "role", "", "Either worker, controller or empty for all roles")
cmd.PersistentFlags().AddFlagSet(config.GetPersistentFlagSet())
return cmd
}
1 change: 0 additions & 1 deletion cmd/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type CmdOpts config.CLIOptions

var (
tokenExpiry string
tokenRole string
waitCreate bool
)

Expand Down
30 changes: 16 additions & 14 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# Architecture

**Note:** As with any young project, things change rapidly. Thus all the details in this architecture documentation may not be always up-to-date, but the high level concepts and patterns should still apply.
**Note:** As k0s is a new and dynamic project, the product architecture may occasionally outpace the documentation. The high level concepts and patterns, however, should always apply.

## Packaging

k0s is packaged as single, self-extracting binary which embeds Kubernetes binaries. This has many benefits:
- Everything can be, and is, statically compiled
- No OS level deps
- No RPMs, dep's, snaps or any other OS specific packaging needed. Single "package" for all OSes
- We can fully control the versions of each and every dependency
The k0s package is a single, self-extracting binary that embeds Kubernetes binaries, the benefits of which include:

- Statically compiled
- No OS-level dependencies
- Requires no RPMs, dependencies, snaps, or any other OS-specific packaging
- Provides a single package for all operating systems
- Allows full version control for each dependency

![k0s packaging as a single binary](img/k0s_packaging.png)

## Control plane

k0s as a single binary acts as the process supervisor for all other control plane components. This means there's no container engine or kubelet running on controllers (by default). Which means there is no way for a cluster user to schedule workloads onto controller nodes.
As a single binary, k0s acts as the process supervisor for all other control plane components. As such, there is no container engine or kubelet running on controllers by default, which thus means that a cluster user cannot schedule workloads onto controller nodes.

![k0s Controller processes](img/k0s_controller_processes.png)

k0s creates, manages and configures each of the components. k0s runs all control plane components as "naked" processes. So on the controller node there's no container engine running.
Using k0s you can create, manage, and configure each of the components, running each as a "naked" process. Thus, there is no container engine running on the controller node.

### Storage
## Storage

Typically Kubernetes control plane supports only etcd as the datastore. In addition to etcd, k0s supports many other datastore options. This is achieved by including [kine](https://github.com/rancher/kine/). Kine allows wide variety of backend data stores to be used such as MySQL, PostgreSQL, SQLite and dqlite. See more in storage [documentation](configuration.md#specstorage)
Kubernetes control plane typically supports only etcd as the datastore. k0s, however, supports many other datastore options in addition to etcd, which it achieves by including [kine](https://github.com/rancher/kine/). Kine allows the use of a wide variety of backend data stores, such as MySQL, PostgreSQL, SQLite, and dqlite (refer to the [`spec.storage` documentation](configuration.md#specstorage)).

In case of k0s managed etcd, k0s manages the full lifecycle of the etcd cluster. This means for example that by joining a new controller node with `k0s controller "long-join-token"` k0s will automatically adjust the etcd cluster membership info to allow the new member to join the cluster.
In the case of k0s managed etcd, k0s manages the full lifecycle of the etcd cluster. For example, by joining a new controller node with `k0s controller "long-join-token"` k0s atomatically adjusts the etcd cluster membership info to allow the new member to join the cluster.

**Note:** Currently k0s cannot shrink the etcd cluster. For now user needs to manually remove the etcd member and only after that shutdown the k0s controller on the removed node.
**Note**: k0s cannot shrink the etcd cluster. As such, to shut down the k0s controller on a node that node must first be manually removed from the etcd cluster.

## Worker node

![k0s worker processes](img/k0s_worker_processes.png)

Like for the control plane, k0s creates and manages the core worker components as naked processes on the worker node.
As with the control plane, with k0s you can create and manage the core worker components as naked processes on the worker node.

By default, k0s workers use [containerd](https://containerd.io) as a high-level runtime and [runc](https://github.com/opencontainers/runc) as a low-level runtime. Custom runtimes are also supported as described [here](custom-cri-runtime.md).
By default, k0s workers use [containerd](https://containerd.io) as a high-level runtime and [runc](https://github.com/opencontainers/runc) as a low-level runtime. Custom runtimes are also supported (refer to [Custom CRI runtime](custom-cri-runtime.md)).
2 changes: 2 additions & 0 deletions docs/cli/k0s.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ k0s - The zero friction Kubernetes - https://k0sproject.io
* [k0s docs](k0s_docs.md) - Generate Markdown docs for the k0s binary
* [k0s etcd](k0s_etcd.md) - Manage etcd cluster
* [k0s install](k0s_install.md) - Helper command for setting up k0s on a brand-new system. Must be run as root (or with sudo)
* [k0s start](k0s_stop.md) - Start the k0s service after it has been installed using `k0s install`. Must be run as root (or with sudo)
* [k0s stop](k0s_stop.md) - Stop the k0s service after it has been installed using `k0s install`. Must be run as root (or with sudo)
* [k0s kubeconfig](k0s_kubeconfig.md) - Create a kubeconfig file for a specified user
* [k0s status](k0s_status.md) - Helper command for get general information about k0s
* [k0s token](k0s_token.md) - Manage join tokens
Expand Down
5 changes: 3 additions & 2 deletions docs/cli/k0s_install.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## k0s install

Helper command for setting up k0s on a brand-new system. Must be run as root (or with sudo)
Helper command for setting up k0s on a brand-new system. Must be run as root (or with sudo).

### Options

Expand All @@ -23,4 +23,5 @@ Helper command for setting up k0s on a brand-new system. Must be run as root (or
* [k0s](k0s.md) - k0s - Zero Friction Kubernetes
* [k0s install controller](k0s_install_controller.md) - Helper command for setting up k0s as controller node on a brand-new system. Must be run as root (or with sudo)
* [k0s install worker](k0s_install_worker.md) - Helper command for setting up k0s as a worker node on a brand-new system. Must be run as root (or with sudo)

* [k0s start](k0s_stop.md) - Start the k0s service after it has been installed using `k0s install`. Must be run as root (or with sudo)
* [k0s stop](k0s_stop.md) - Stop the k0s service after it has been installed using `k0s install`. Must be run as root (or with sudo)
22 changes: 22 additions & 0 deletions docs/cli/k0s_start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## k0s start

Start the k0s service after it has been installed using `k0s install`. Must be run as root (or with sudo),

### Options

```
-h, --help help for start
```

### Options inherited from parent commands

```
-d, --debug Debug logging (default: false)
```

### SEE ALSO

* [k0s stop](k0s_stop.md) - Stop the k0s service after it has been installed using `k0s install`. Must be run as root (or with sudo)
* [k0s install](k0s_install.md) - Helper command for setting up k0s on a brand-new system. Must be run as root (or with sudo)
* [k0s install controller](k0s_install_controller.md) - Helper command for setting up k0s as controller node on a brand-new system. Must be run as root (or with sudo)
* [k0s install worker](k0s_install_worker.md) - Helper command for setting up k0s as a worker node on a brand-new system. Must be run as root (or with sudo)

0 comments on commit c80fabd

Please sign in to comment.