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

Workloads API #3202

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/kubermatic-labs/boilerplate v0.3.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.9 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubermatic-labs/boilerplate v0.3.0 h1:fxQX7wUGi//PsUhm7BHd2IVFTexDw9q7g0WxgFENQu0=
github.com/kubermatic-labs/boilerplate v0.3.0/go.mod h1:ZVHejB7QRpf39tegpJDHyduszC5LQGRC9GAi70m4aSk=
github.com/kubermatic/machine-controller v1.57.3 h1:i17ieepdav0q7zAoYRsxOwdZD4dQe4zDI5saqTR2CbI=
github.com/kubermatic/machine-controller v1.57.3/go.mod h1:vjuE/IcTxlRu4etiDyPasc4O7IcnKMgGl0zbcCjXgvs=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/kubeone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ type KubeOneCluster struct {
// --namespace <NAMESPACE> --install --create-namespace <RELEASE> <CHART> [--values=values-override.yaml]`
HelmReleases []HelmRelease `json:"helmReleases,omitempty"`

// Workloads
Workloads []Workload `json:"workloads,omitempty"`

// SystemPackages configure kubeone behaviour regarding OS packages.
SystemPackages *SystemPackages `json:"systemPackages,omitempty"`

Expand All @@ -98,6 +101,15 @@ type KubeOneCluster struct {
ControlPlaneComponents *ControlPlaneComponents `json:"controlPlaneComponents,omitempty"`
}

// Workload
type Workload struct {
// Addon
Addon *Addon `json:"addon,omitempty"`

// HelmRelease
HelmRelease *HelmRelease `json:"helmRelease,omitempty"`
}

type ControlPlaneComponents struct {
// ControllerManagerConfig configures the Kubernetes Controller Manager
ControllerManager *ControlPlaneComponentConfig `json:"controllerManager,omitempty"`
Expand Down
1 change: 1 addition & 0 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.

19 changes: 16 additions & 3 deletions pkg/apis/kubeone/v1beta2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func SetDefaults_KubeOneCluster(obj *KubeOneCluster) {
SetDefaults_MachineController(obj)
SetDefaults_OperatingSystemManager(obj)
SetDefaults_HelmReleases(obj)
SetDefaults_Workloads(obj)
SetDefaults_SystemPackages(obj)
SetDefaults_Features(obj)
SetDefaults_CloudConfig(obj)
Expand Down Expand Up @@ -249,10 +250,22 @@ func SetDefaults_OperatingSystemManager(obj *KubeOneCluster) {
}
}

func defaulHelmRelease(hr *HelmRelease) {
if hr.ReleaseName == "" {
hr.ReleaseName = hr.Chart
}
}

func SetDefaults_HelmReleases(obj *KubeOneCluster) {
for idx, hr := range obj.HelmReleases {
if hr.ReleaseName == "" {
obj.HelmReleases[idx].ReleaseName = hr.Chart
for idx := range obj.HelmReleases {
defaulHelmRelease(&obj.HelmReleases[idx])
}
}

func SetDefaults_Workloads(obj *KubeOneCluster) {
for idx, wk := range obj.Workloads {
if wk.HelmRelease != nil {
defaulHelmRelease(obj.Workloads[idx].HelmRelease)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/kubeone/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ type KubeOneCluster struct {
// --namespace <NAMESPACE> --install --create-namespace <RELEASE> <CHART> [--values=values-override.yaml]`
HelmReleases []HelmRelease `json:"helmReleases,omitempty"`

// Workloads
Workloads []Workload `json:"workloads,omitempty"`

// SystemPackages configure kubeone behaviour regarding OS packages.
SystemPackages *SystemPackages `json:"systemPackages,omitempty"`

Expand All @@ -95,6 +98,15 @@ type KubeOneCluster struct {
ControlPlaneComponents *ControlPlaneComponents `json:"controlPlaneComponents,omitempty"`
}

// Workload
type Workload struct {
// Addon
Addon *Addon `json:"addon,omitempty"`

// HelmRelease
HelmRelease *HelmRelease `json:"helmRelease,omitempty"`
}

type ControlPlaneComponents struct {
// ControllerManagerConfig configures the Kubernetes Controller Manager
ControllerManager *ControlPlaneComponentConfig `json:"controllerManager,omitempty"`
Expand Down
34 changes: 34 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.

33 changes: 33 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: 16 additions & 1 deletion pkg/apis/kubeone/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (

"github.com/Masterminds/semver/v3"

"k8c.io/kubeone/pkg/addons"
kubeoneapi "k8c.io/kubeone/pkg/apis/kubeone"
"k8c.io/kubeone/pkg/semverutil"
"k8c.io/kubeone/pkg/workloads/addons"

"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -78,6 +78,7 @@ func ValidateKubeOneCluster(c kubeoneapi.KubeOneCluster) field.ErrorList {
allErrs = append(allErrs, ValidateFeatures(c.Features, c.Versions, field.NewPath("features"))...)
allErrs = append(allErrs, ValidateAddons(c.Addons, field.NewPath("addons"))...)
allErrs = append(allErrs, ValidateHelmReleases(c.HelmReleases, field.NewPath("helmReleases"))...)
allErrs = append(allErrs, ValidateWorkloads(c.Workloads, field.NewPath("workloads"))...)
allErrs = append(allErrs, ValidateRegistryConfiguration(c.RegistryConfiguration, field.NewPath("registryConfiguration"))...)
allErrs = append(allErrs, ValidateControlPlaneComponents(c.ControlPlaneComponents, field.NewPath("controlPlaneComponents"))...)
allErrs = append(allErrs,
Expand Down Expand Up @@ -731,6 +732,20 @@ func ValidateHelmReleases(helmReleases []kubeoneapi.HelmRelease, fldPath *field.
return allErrs
}

func ValidateWorkloads(workloads []kubeoneapi.Workload, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

for _, wk := range workloads {
switch {
case wk.Addon != nil:
case wk.HelmRelease != nil:
allErrs = append(allErrs, ValidateHelmReleases([]kubeoneapi.HelmRelease{*wk.HelmRelease}, fldPath)...)
}
}

return allErrs
}

// ValidateHostConfig validates the HostConfig structure
func ValidateHostConfig(hosts []kubeoneapi.HostConfig, clusterNetwork kubeoneapi.ClusterNetworkConfig, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
Expand Down
33 changes: 33 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.

2 changes: 1 addition & 1 deletion pkg/cmd/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8c.io/kubeone/pkg/addons"
"k8c.io/kubeone/pkg/workloads/addons"
)

func addonsCmd(rootFlags *pflag.FlagSet) *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8c.io/kubeone/pkg/addons"
kubeoneapi "k8c.io/kubeone/pkg/apis/kubeone"
"k8c.io/kubeone/pkg/apis/kubeone/config"
kubeonev1beta2 "k8c.io/kubeone/pkg/apis/kubeone/v1beta2"
kubeonevalidation "k8c.io/kubeone/pkg/apis/kubeone/validation"
"k8c.io/kubeone/pkg/executor"
"k8c.io/kubeone/pkg/fail"
"k8c.io/kubeone/pkg/state"
"k8c.io/kubeone/pkg/workloads/addons"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
8 changes: 3 additions & 5 deletions pkg/cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ import (
"github.com/spf13/pflag"
"golang.org/x/term"

"k8c.io/kubeone/pkg/addons"
kubeoneapi "k8c.io/kubeone/pkg/apis/kubeone"
"k8c.io/kubeone/pkg/apis/kubeone/config"
"k8c.io/kubeone/pkg/credentials"
"k8c.io/kubeone/pkg/fail"
"k8c.io/kubeone/pkg/state"
"k8c.io/kubeone/pkg/workloads/addons"

"k8s.io/apimachinery/pkg/util/sets"
ctrlruntimelog "sigs.k8s.io/controller-runtime/pkg/log"
)

var (
defaultKubeVersion = ""
)
var defaultKubeVersion = ""

const yes = "yes"

Expand Down Expand Up @@ -248,7 +246,7 @@ func initBackup(backupPath string) error {
}

// try to write to the file before doing anything else
backup, err := os.OpenFile(backupPath, os.O_RDWR|os.O_CREATE, 0600)
backup, err := os.OpenFile(backupPath, os.O_RDWR|os.O_CREATE, 0o600)
if err != nil {
return fail.Runtime(err, "opening backup file for write")
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func File(st *state.State) (*os.File, func(), error) {
konfigBuf, err := Download(st)
if err != nil {
return nil, nil, err
}

tmpKubeConf, err := os.CreateTemp("", "kubeone-kubeconfig-*")
if err != nil {
return nil, nil, fail.Runtime(err, "creating temp file for helm kubeconfig")
}

cleanupFn := func() {
name := tmpKubeConf.Name()
tmpKubeConf.Close()
os.Remove(name)
}

n, err := tmpKubeConf.Write(konfigBuf)
if err != nil {
cleanupFn()

return nil, nil, fail.Runtime(err, "wring temp file for helm kubeconfig")
}
if n != len(konfigBuf) {
cleanupFn()

return nil, nil, fail.NewRuntimeError("incorrect number of bytes written to temp kubeconfig", "")
}

return tmpKubeConf, cleanupFn, nil
}

// Download downloads Kubeconfig over SSH
func Download(s *state.State) ([]byte, error) {
// connect to host
Expand Down
Loading