Skip to content

Commit

Permalink
Move cilium bootstrap logic to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Dec 11, 2020
1 parent acb7608 commit a91d3d3
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 72 deletions.
1 change: 1 addition & 0 deletions upup/pkg/fi/cloudup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ go_test(
"//upup/models:go_default_library",
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/cloudup/awsup:go_default_library",
"//upup/pkg/fi/cloudup/bootstrapchannelbuilder:go_default_library",
"//upup/pkg/fi/fitasks:go_default_library",
"//util/pkg/architectures:go_default_library",
"//util/pkg/hashing:go_default_library",
Expand Down
5 changes: 4 additions & 1 deletion upup/pkg/fi/cloudup/bootstrapchannelbuilder/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["bootstrapchannelbuilder.go"],
srcs = [
"bootstrapchannelbuilder.go",
"cilium.go",
],
importpath = "k8s.io/kops/upup/pkg/fi/cloudup/bootstrapchannelbuilder",
visibility = ["//visibility:public"],
deps = [
Expand Down
106 changes: 35 additions & 71 deletions upup/pkg/fi/cloudup/bootstrapchannelbuilder/bootstrapchannelbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"fmt"
"strings"

"github.com/blang/semver/v4"

"k8s.io/klog/v2"
channelsapi "k8s.io/kops/channels/pkg/api"
"k8s.io/kops/pkg/apis/kops"
Expand Down Expand Up @@ -49,6 +47,29 @@ type BootstrapChannelBuilder struct {

var _ fi.ModelBuilder = &BootstrapChannelBuilder{}

// networkSelector is the labels set on networking addons
//
// The role.kubernetes.io/networking is used to label anything related to a networking addin,
// so that if we switch networking plugins (e.g. calico -> weave or vice-versa), we'll replace the
// old networking plugin, and there won't be old pods "floating around".
//
// This means whenever we create or update a networking plugin, we should be sure that:
// 1. the selector is role.kubernetes.io/networking=1
// 2. every object in the manifest is labeled with role.kubernetes.io/networking=1
//
// TODO: Some way to test/enforce this?
//
// TODO: Create "empty" configurations for others, so we can delete e.g. the kopeio configuration
// if we switch to kubenet?
//
// TODO: Create configuration object for cni providers (maybe create it but orphan it)?
//
// NOTE: we try to suffix with -kops.1, so that we can increment versions even if the upstream version
// hasn't changed. The problem with semver is that there is nothing > 1.0.0 other than 1.0.1-pre.1
func networkingSelector() map[string]string {
return map[string]string{"role.kubernetes.io/networking": "1"}
}

// NewBootstrapChannelBuilder creates a new BootstrapChannelBuilder
func NewBootstrapChannelBuilder(modelContext *model.KopsModelContext,
clusterLifecycle *fi.Lifecycle, assetBuilder *assets.AssetBuilder,
Expand Down Expand Up @@ -666,25 +687,6 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
}
}

// The role.kubernetes.io/networking is used to label anything related to a networking addin,
// so that if we switch networking plugins (e.g. calico -> weave or vice-versa), we'll replace the
// old networking plugin, and there won't be old pods "floating around".

// This means whenever we create or update a networking plugin, we should be sure that:
// 1. the selector is role.kubernetes.io/networking=1
// 2. every object in the manifest is labeled with role.kubernetes.io/networking=1

// TODO: Some way to test/enforce this?

// TODO: Create "empty" configurations for others, so we can delete e.g. the kopeio configuration
// if we switch to kubenet?

// TODO: Create configuration object for cni providers (maybe create it but orphan it)?

// NOTE: we try to suffix with -kops.1, so that we can increment versions even if the upstream version
// hasn't changed. The problem with semver is that there is nothing > 1.0.0 other than 1.0.1-pre.1
networkingSelector := map[string]string{"role.kubernetes.io/networking": "1"}

if b.Cluster.Spec.Networking.Kopeio != nil {
key := "networking.kope.io"
version := "1.0.20181028-kops.2"
Expand All @@ -696,7 +698,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(version),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
Id: id,
})
Expand All @@ -716,7 +718,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
Id: id,
})
Expand All @@ -736,7 +738,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
Id: id,
})
Expand All @@ -757,7 +759,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
KubernetesVersion: "<1.16.0",
Id: id,
Expand All @@ -771,7 +773,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
KubernetesVersion: ">=1.16.0",
Id: id,
Expand All @@ -793,7 +795,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
KubernetesVersion: "<1.15.0",
Id: id,
Expand All @@ -806,7 +808,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
KubernetesVersion: ">=1.15.0 <1.16.0",
Id: id,
Expand All @@ -819,7 +821,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
KubernetesVersion: ">=1.16.0",
Id: id,
Expand All @@ -840,7 +842,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
Id: id,
})
Expand All @@ -862,7 +864,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
KubernetesVersion: "<1.16.0",
Id: id,
Expand All @@ -876,53 +878,15 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.ModelBuilderContext) (*chann
addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(versions[id]),
Selector: networkingSelector,
Selector: networkingSelector(),
Manifest: fi.String(location),
KubernetesVersion: ">=1.16.0",
Id: id,
})
}
}

cilium := b.Cluster.Spec.Networking.Cilium
if cilium != nil {
ver, _ := semver.ParseTolerant(cilium.Version)
ver.Build = nil
ver.Pre = nil
v8, _ := semver.Parse("1.8.0")
key := "networking.cilium.io"
if ver.LT(v8) {
version := "1.7.3-kops.1"

{
id := "k8s-1.12"
location := key + "/" + id + ".yaml"

addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(version),
Selector: networkingSelector,
Manifest: fi.String(location),
Id: id,
})
}
} else {
version := "1.8.0-kops.1"
{
id := "k8s-1.12"
location := key + "/" + id + "-v1.8.yaml"

addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(version),
Selector: networkingSelector,
Manifest: fi.String(location),
Id: id,
NeedsRollingUpdate: "all",
})
}
}
}
addCiliumAddon(b, addons)

authenticationSelector := map[string]string{"role.kubernetes.io/authentication": "1"}

Expand Down
68 changes: 68 additions & 0 deletions upup/pkg/fi/cloudup/bootstrapchannelbuilder/cilium.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright 2020 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.
*/

package bootstrapchannelbuilder

import (
"github.com/blang/semver/v4"
"k8s.io/kops/channels/pkg/api"
channelsapi "k8s.io/kops/channels/pkg/api"
"k8s.io/kops/upup/pkg/fi"
)

func addCiliumAddon(b *BootstrapChannelBuilder, addons *api.Addons) {

cilium := b.Cluster.Spec.Networking.Cilium
if cilium != nil {
ver, _ := semver.ParseTolerant(cilium.Version)
ver.Build = nil
ver.Pre = nil
v8, _ := semver.Parse("1.8.0")
key := "networking.cilium.io"
if ver.LT(v8) {
version := "1.7.3-kops.1"

{
id := "k8s-1.12"
location := key + "/" + id + ".yaml"

addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(version),
Selector: networkingSelector(),
Manifest: fi.String(location),
Id: id,
})
}
} else {
version := "1.8.0-kops.1"
{
id := "k8s-1.12"
location := key + "/" + id + "-v1.8.yaml"

addons.Spec.Addons = append(addons.Spec.Addons, &channelsapi.AddonSpec{
Name: fi.String(key),
Version: fi.String(version),
Selector: networkingSelector(),
Manifest: fi.String(location),
Id: id,
NeedsRollingUpdate: "all",
})
}
}
}

}
Loading

0 comments on commit a91d3d3

Please sign in to comment.