Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add container logs max size to the kubeone API #1644

Merged
merged 45 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
eb88bf0
feat: add flag for container logs max size
nerdeveloper Nov 23, 2021
f2f07eb
feat: remove container log max size flag add it the kubeone api
nerdeveloper Nov 24, 2021
15974e9
chore: update value of the container logs constructor
nerdeveloper Nov 24, 2021
aa4bf83
chore: update
nerdeveloper Nov 24, 2021
f069eb1
refactor: add kubeconfig object to the kubeone API to support kubelet…
nerdeveloper Nov 25, 2021
d3ee2b3
chore: update code gen
nerdeveloper Nov 25, 2021
347693c
chore: update code gen
nerdeveloper Nov 25, 2021
649812a
chore: sort goimports
nerdeveloper Nov 25, 2021
138b730
chore: update code
nerdeveloper Jan 5, 2022
05bde00
chore: merge code
nerdeveloper Jan 5, 2022
99b9a48
refactor: remove container log max size from old API and add to new one
nerdeveloper Jan 5, 2022
c38aa82
chore: remove flags for container log max size
nerdeveloper Jan 5, 2022
604dd36
chore: add conversion
nerdeveloper Jan 5, 2022
642810f
Update pkg/cmd/config.go
nerdeveloper Jan 5, 2022
be86817
chore: add conversion
nerdeveloper Jan 5, 2022
a515c7b
docs: update API docs
nerdeveloper Jan 5, 2022
6fa119f
docs: revert to Top level API
nerdeveloper Jan 7, 2022
a68236f
docs: update lint
nerdeveloper Jan 7, 2022
b4b6ae4
Merge branch 'master' into add/container-log-size
nerdeveloper Jan 12, 2022
8027737
Update pkg/apis/kubeone/types.go
nerdeveloper Jan 21, 2022
d4a733c
Merge branch 'kubermatic:master' into add/container-log-size
nerdeveloper Jan 24, 2022
eb949c3
refactor: change container max log size
nerdeveloper Jan 24, 2022
ea00044
Merge branch 'add/container-log-size' of https://github.com/nerdevelo…
nerdeveloper Jan 24, 2022
871a091
chore: update kubeone api
nerdeveloper Jan 24, 2022
eb70c24
Add skip of LoggingConfig{} conversion in v1beta1 API
kron4eg Jan 24, 2022
96a34be
chore: update api defaulting
nerdeveloper Jan 25, 2022
2f4cd2e
chore: fix linting issue
nerdeveloper Jan 25, 2022
9ca7c21
Update pkg/apis/kubeone/types.go
nerdeveloper Jan 25, 2022
4553a37
Update pkg/apis/kubeone/types.go
nerdeveloper Jan 25, 2022
213feed
chore: add docker CRI checks
nerdeveloper Jan 26, 2022
79a4d58
chore: rebase from master
nerdeveloper Jan 26, 2022
67932d1
chore: fix linting issue
nerdeveloper Jan 26, 2022
f1bb451
test: update go tests
nerdeveloper Jan 26, 2022
78fea32
Update pkg/cmd/config.go
nerdeveloper Jan 26, 2022
8979029
chore: update values
nerdeveloper Jan 26, 2022
8f3dee6
chore: update values
nerdeveloper Jan 26, 2022
2340768
test: add test to check if log size parses
nerdeveloper Jan 26, 2022
a7666d1
chore: fix lint issue
nerdeveloper Jan 26, 2022
b0963e3
Update pkg/apis/kubeone/v1beta2/types.go
nerdeveloper Jan 27, 2022
430c5e0
Update pkg/apis/kubeone/config/config.go
nerdeveloper Jan 27, 2022
c0ecbb0
Update pkg/cmd/config.go
nerdeveloper Jan 27, 2022
f24d3ad
Update pkg/containerruntime/docker_config_test.go
nerdeveloper Jan 27, 2022
e991ba0
chore: add suggestion and update tests
nerdeveloper Jan 27, 2022
fa11297
chore: fix linting
nerdeveloper Jan 27, 2022
486f984
Add boilerplate to docker_config_test.go
kron4eg Jan 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api_reference/v1beta1.en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "v1beta1 API Reference"
date = 2021-12-23T21:13:02+05:00
date = 2022-01-28T02:22:19+04:00
weight = 11
+++
## v1beta1
Expand Down
14 changes: 13 additions & 1 deletion docs/api_reference/v1beta2.en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = "v1beta2 API Reference"
date = 2022-01-11T11:06:38+02:00
date = 2022-01-28T02:22:19+04:00
weight = 11
+++
## v1beta2
Expand Down Expand Up @@ -40,6 +40,7 @@ weight = 11
* [KubeOneCluster](#kubeonecluster)
* [KubeProxyConfig](#kubeproxyconfig)
* [KubeletConfig](#kubeletconfig)
* [LoggingConfig](#loggingconfig)
* [MachineControllerConfig](#machinecontrollerconfig)
* [MetricsServer](#metricsserver)
* [NoneSpec](#nonespec)
Expand Down Expand Up @@ -460,6 +461,7 @@ KubeOneCluster is KubeOne Cluster API Schema
| addons | Addons are used to deploy additional manifests. | *[Addons](#addons) | false |
| systemPackages | SystemPackages configure kubeone behaviour regarding OS packages. | *[SystemPackages](#systempackages) | false |
| registryConfiguration | RegistryConfiguration configures how Docker images are pulled from an image registry | *[RegistryConfiguration](#registryconfiguration) | false |
| loggingConfig | LoggingConfig configures the Kubelet's log configuration | [LoggingConfig](#loggingconfig) | false |

[Back to Group](#v1beta2)

Expand Down Expand Up @@ -487,6 +489,16 @@ KubeletConfig provides some kubelet configuration options

[Back to Group](#v1beta2)

### LoggingConfig

LoggingConfig configures the Kubelet's log rotation

| Field | Description | Scheme | Required |
| ----- | ----------- | ------ | -------- |
| containerLogMaxSize | ContainerLogMaxSize configures the maximum size of container log file before it is rotated See more at: https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/ | string | false |

[Back to Group](#v1beta2)

### MachineControllerConfig

MachineControllerConfig configures kubermatic machine-controller deployment
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/kubeone/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ func SetKubeOneClusterDynamicDefaults(cluster *kubeoneapi.KubeOneCluster, creden
}
}

// Default ContainerLogMaxSize.
// NB: We intentionally default here because LoggingConfig is not available in
// the v1beta1 API. If we would default in the v1beta2 API instead, this value would
// be empty when converting from v1beta1 to internal. This means that v1beta1 API
// users would depend on default values provided by Docker/upstream, which are
// different than our default values, so we want to avoid this.
if cluster.LoggingConfig.ContainerLogMaxSize == "" {
cluster.LoggingConfig.ContainerLogMaxSize = "100Mi"
kron4eg marked this conversation as resolved.
Show resolved Hide resolved
}

// Default the AssetsConfiguration internal API
cluster.DefaultAssetConfiguration()

Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/kubeone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ type KubeOneCluster struct {
AssetConfiguration AssetConfiguration `json:"assetConfiguration,omitempty"`
// RegistryConfiguration configures how Docker images are pulled from an image registry
RegistryConfiguration *RegistryConfiguration `json:"registryConfiguration,omitempty"`
// LoggingConfig configures the Kubelet's log rotation
LoggingConfig LoggingConfig `json:"loggingConfig,omitempty"`
}

// LoggingConfig configures the Kubelet's log rotation
type LoggingConfig struct {
// ContainerLogMaxSize configures the maximum size of container log file before it is rotated
// See more at: https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/
ContainerLogMaxSize string `json:"containerLogMaxSize,omitempty"`
}

// ContainerRuntimeConfig
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/kubeone/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ func Convert_kubeone_HostConfig_To_v1beta1_HostConfig(in *kubeone.HostConfig, ou
// explicitly skip kubelet conversion omitted in autoConvert_kubeone_HostConfig_To_v1beta1_HostConfig
return autoConvert_kubeone_HostConfig_To_v1beta1_HostConfig(in, out, scope)
}

func Convert_kubeone_KubeOneCluster_To_v1beta1_KubeOneCluster(in *kubeone.KubeOneCluster, out *KubeOneCluster, s conversion.Scope) error {
// LoggingConfig was introduced only in new v1beta2 API, so we skip it here
return autoConvert_kubeone_KubeOneCluster_To_v1beta1_KubeOneCluster(in, out, s)
}
16 changes: 6 additions & 10 deletions pkg/apis/kubeone/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/apis/kubeone/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ type KubeOneCluster struct {
SystemPackages *SystemPackages `json:"systemPackages,omitempty"`
// RegistryConfiguration configures how Docker images are pulled from an image registry
RegistryConfiguration *RegistryConfiguration `json:"registryConfiguration,omitempty"`
// LoggingConfig configures the Kubelet's log configuration
LoggingConfig LoggingConfig `json:"loggingConfig,omitempty"`
}

// LoggingConfig configures the Kubelet's log rotation
type LoggingConfig struct {
// ContainerLogMaxSize configures the maximum size of container log file before it is rotated
// See more at: https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/
ContainerLogMaxSize string `json:"containerLogMaxSize,omitempty"`
}

// ContainerRuntimeConfig
Expand Down
36 changes: 36 additions & 0 deletions pkg/apis/kubeone/v1beta2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/apis/kubeone/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/apis/kubeone/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type printOpts struct {
EnableEncryptionProviders bool `longflag:"enable-encryption-providers"`

DeployMachineController bool `longflag:"deploy-machine-controller"`

ContainerLogMaxSize string `longflag:"container-log-max-size"`
}

// configCmd setups the config command
Expand Down Expand Up @@ -174,6 +176,14 @@ func configPrintCmd() *cobra.Command {
// MachineController
cmd.Flags().BoolVar(&opts.DeployMachineController, longFlagName(opts, "DeployMachineController"), true, "deploy kubermatic machine-controller")

// LoggingConfig
cmd.Flags().StringVarP(
&opts.ContainerLogMaxSize,
longFlagName(opts, "ContainerLogMaxSize"),
shortFlagName(opts, "ContainerLogMaxSize"),
"100Mi",
"ContainerLogMaxSize")

return cmd
}

Expand Down Expand Up @@ -370,6 +380,8 @@ func createAndPrintManifest(printOptions *printOpts) error {
cfg.Set(yamled.Path{"machineController", "deploy"}, printOptions.DeployMachineController)
}

cfg.Set(yamled.Path{"loggingConfig", "containerLogMaxSize"}, printOptions.ContainerLogMaxSize)

// Print the manifest
err := validateAndPrintConfig(cfg)
if err != nil {
Expand Down Expand Up @@ -972,4 +984,7 @@ machineController:
# operatingSystem: 'ubuntu'
# operatingSystemSpec:
# distUpgradeOnBoot: true

loggingConfig:
containerLogMaxSize: "{{ .ContainerLogMaxSize }}"
`
8 changes: 7 additions & 1 deletion pkg/containerruntime/docker_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package containerruntime

import (
"encoding/json"
"strings"

"k8c.io/kubeone/pkg/apis/kubeone"
)
Expand All @@ -32,12 +33,17 @@ type dockerConfig struct {
}

func marshalDockerConfig(cluster *kubeone.KubeOneCluster) (string, error) {
logSize := strings.ToLower(cluster.LoggingConfig.ContainerLogMaxSize)
logSize = strings.ReplaceAll(logSize, "ki", "k")
logSize = strings.ReplaceAll(logSize, "mi", "m")
kron4eg marked this conversation as resolved.
Show resolved Hide resolved
logSize = strings.ReplaceAll(logSize, "gi", "g")

cfg := dockerConfig{
ExecOpts: []string{"native.cgroupdriver=systemd"},
StorageDriver: "overlay2",
LogDriver: "json-file",
LogOpts: map[string]string{
"max-size": "100m",
"max-size": logSize,
},
}

Expand Down
Loading