Skip to content

Commit

Permalink
Merge pull request #12123 from olemarkus/node-unattended-upgrades
Browse files Browse the repository at this point in the history
Fix disabling unattended upgrades
  • Loading branch information
k8s-ci-robot committed Aug 10, 2021
2 parents 8e5d1e4 + f1a8565 commit c2ff89a
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 6 deletions.
1 change: 1 addition & 0 deletions nodeup/pkg/model/BUILD.bazel

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

8 changes: 8 additions & 0 deletions nodeup/pkg/model/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/kops/pkg/testutils"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup"
"k8s.io/kops/util/pkg/distributions"
"k8s.io/kops/util/pkg/vfs"
)

Expand Down Expand Up @@ -298,6 +299,11 @@ func BuildNodeupModelContext(model *testutils.Model) (*NodeupModelContext, error
}

nodeupModelContext.NodeupConfig.ContainerdConfig = nodeupModelContext.Cluster.Spec.Containerd
updatePolicy := nodeupModelContext.Cluster.Spec.UpdatePolicy
if updatePolicy == nil {
updatePolicy = fi.String(kops.UpdatePolicyAutomatic)
}
nodeupModelContext.NodeupConfig.UpdatePolicy = *updatePolicy

return nodeupModelContext, nil
}
Expand Down Expand Up @@ -397,6 +403,8 @@ func RunGoldenTest(t *testing.T, basedir string, key string, builder func(*Nodeu

nodeupModelContext.KeyStore = keystore

nodeupModelContext.Distribution = distributions.DistributionUbuntu2004

if err := nodeupModelContext.Init(); err != nil {
t.Fatalf("error from nodeupModelContext.Init(): %v", err)
}
Expand Down
64 changes: 64 additions & 0 deletions nodeup/pkg/model/tests/updateservicebuilder/automatic/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: kops.k8s.io/v1alpha2
kind: Cluster
metadata:
creationTimestamp: "2016-12-10T22:42:27Z"
name: minimal.example.com
spec:
kubernetesApiAccess:
- 0.0.0.0/0
channel: stable
cloudProvider: aws
configBase: memfs://clusters.example.com/minimal.example.com
containerd:
version: 1.3.4
containerRuntime: containerd
etcdClusters:
- etcdMembers:
- instanceGroup: master-us-test-1a
name: master-us-test-1a
name: main
provider: Manager
- etcdMembers:
- instanceGroup: master-us-test-1a
name: master-us-test-1a
name: events
provider: Manager
iam: {}
kubelet:
hostnameOverride: master.hostname.invalid
kubernetesVersion: v1.17.0
masterInternalName: api.internal.minimal.example.com
masterPublicName: api.minimal.example.com
networkCIDR: 172.20.0.0/16
networking:
calico: {}
nonMasqueradeCIDR: 100.64.0.0/10
sshAccess:
- 0.0.0.0/0
topology:
masters: public
nodes: public
subnets:
- cidr: 172.20.32.0/19
name: us-test-1a
type: Public
zone: us-test-1a

---

apiVersion: kops.k8s.io/v1alpha2
kind: InstanceGroup
metadata:
creationTimestamp: "2016-12-10T22:42:28Z"
name: master-1a
labels:
kops.k8s.io/cluster: minimal.example.com
spec:
associatePublicIp: true
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
machineType: t2.medium
maxSize: 2
minSize: 2
role: Master
subnets:
- us-test-1a
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contents: |
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
path: /etc/apt/apt.conf.d/20auto-upgrades
type: file
---
Name: unattended-upgrades
64 changes: 64 additions & 0 deletions nodeup/pkg/model/tests/updateservicebuilder/external/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: kops.k8s.io/v1alpha2
kind: Cluster
metadata:
creationTimestamp: "2016-12-10T22:42:27Z"
name: minimal.example.com
spec:
kubernetesApiAccess:
- 0.0.0.0/0
channel: stable
cloudProvider: aws
configBase: memfs://clusters.example.com/minimal.example.com
containerd:
version: 1.3.4
containerRuntime: containerd
etcdClusters:
- etcdMembers:
- instanceGroup: master-us-test-1a
name: master-us-test-1a
name: main
provider: Manager
- etcdMembers:
- instanceGroup: master-us-test-1a
name: master-us-test-1a
name: events
provider: Manager
iam: {}
kubelet:
hostnameOverride: master.hostname.invalid
kubernetesVersion: v1.17.0
masterInternalName: api.internal.minimal.example.com
masterPublicName: api.minimal.example.com
networkCIDR: 172.20.0.0/16
networking:
calico: {}
nonMasqueradeCIDR: 100.64.0.0/10
sshAccess:
- 0.0.0.0/0
topology:
masters: public
nodes: public
subnets:
- cidr: 172.20.32.0/19
name: us-test-1a
type: Public
zone: us-test-1a
updatePolicy: external
---

apiVersion: kops.k8s.io/v1alpha2
kind: InstanceGroup
metadata:
creationTimestamp: "2016-12-10T22:42:28Z"
name: master-1a
labels:
kops.k8s.io/cluster: minimal.example.com
spec:
associatePublicIp: true
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
machineType: t2.medium
maxSize: 2
minSize: 2
role: Master
subnets:
- us-test-1a
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contents: |
APT::Periodic::Enable "0";
path: /etc/apt/apt.conf.d/20auto-upgrades
type: file
16 changes: 10 additions & 6 deletions nodeup/pkg/model/update_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,27 @@ func (b *UpdateServiceBuilder) buildFlatcarSystemdService(c *fi.ModelBuilderCont
}

func (b *UpdateServiceBuilder) buildDebianPackage(c *fi.ModelBuilderContext) {
if b.NodeupConfig.UpdatePolicy != kops.UpdatePolicyExternal {
contents := ""
if b.NodeupConfig.UpdatePolicy == kops.UpdatePolicyExternal {
klog.Infof("UpdatePolicy requests automatic updates; skipping installation of package %q", debianPackageName)
return
}
contents = `APT::Periodic::Enable "0";
`
} else {

klog.Infof("Detected OS %s; installing %s package", b.Distribution, debianPackageName)
klog.Infof("Detected OS %s; installing %s package", b.Distribution, debianPackageName)
c.AddTask(&nodetasks.Package{Name: debianPackageName})

contents := `APT::Periodic::Update-Package-Lists "1";
contents = `APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
`
}

c.AddTask(&nodetasks.File{
Path: "/etc/apt/apt.conf.d/20auto-upgrades",
Contents: fi.NewStringResource(contents),
Type: nodetasks.FileType_File,
})

c.AddTask(&nodetasks.Package{Name: debianPackageName})
}
38 changes: 38 additions & 0 deletions nodeup/pkg/model/update_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2021 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 model

import (
"testing"

"k8s.io/kops/upup/pkg/fi"
)

func TestUpdateServiceBuilderAutomaticUpgrade(t *testing.T) {
RunGoldenTest(t, "tests/updateservicebuilder/automatic", "updateservice", func(nodeupModelContext *NodeupModelContext, target *fi.ModelBuilderContext) error {
builder := UpdateServiceBuilder{NodeupModelContext: nodeupModelContext}
return builder.Build(target)
})
}

func TestUpdateServiceBuilderExternal(t *testing.T) {
RunGoldenTest(t, "tests/updateservicebuilder/external", "updateservice", func(nodeupModelContext *NodeupModelContext, target *fi.ModelBuilderContext) error {
builder := UpdateServiceBuilder{NodeupModelContext: nodeupModelContext}
return builder.Build(target)
})

}

0 comments on commit c2ff89a

Please sign in to comment.