Skip to content

Commit 21e0cc8

Browse files
Image-builder: Update kernel and keep only 1 kernel on redhat machines
1 parent 4318aa7 commit 21e0cc8

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
From 39a06391908f873f747f22d49682ec7d6009a7af Mon Sep 17 00:00:00 2001
2+
From: Vignesh Goutham Ganesh <[email protected]>
3+
Date: Thu, 14 Dec 2023 15:36:28 -0600
4+
Subject: [PATCH] Remove old kernels
5+
6+
Signed-off-by: Vignesh Goutham Ganesh <[email protected]>
7+
---
8+
images/capi/ansible/roles/node/tasks/main.yml | 3 ++
9+
.../capi/ansible/roles/node/tasks/redhat.yml | 32 +++++++++++++++++++
10+
.../capi/ansible/roles/setup/tasks/redhat.yml | 2 +-
11+
3 files changed, 36 insertions(+), 1 deletion(-)
12+
create mode 100644 images/capi/ansible/roles/node/tasks/redhat.yml
13+
14+
diff --git a/images/capi/ansible/roles/node/tasks/main.yml b/images/capi/ansible/roles/node/tasks/main.yml
15+
index f9f6b9040..9120073b8 100644
16+
--- a/images/capi/ansible/roles/node/tasks/main.yml
17+
+++ b/images/capi/ansible/roles/node/tasks/main.yml
18+
@@ -18,6 +18,9 @@
19+
- import_tasks: amazonLinux2.yml
20+
when: ansible_distribution == "Amazon"
21+
22+
+- import_tasks: redhat.yml
23+
+ when: ansible_distribution == "RedHat"
24+
+
25+
# This is required until https://github.com/ansible/ansible/issues/77537 is fixed and used.
26+
- name: Override Flatcar's OS family
27+
set_fact:
28+
diff --git a/images/capi/ansible/roles/node/tasks/redhat.yml b/images/capi/ansible/roles/node/tasks/redhat.yml
29+
new file mode 100644
30+
index 000000000..b2133b6f1
31+
--- /dev/null
32+
+++ b/images/capi/ansible/roles/node/tasks/redhat.yml
33+
@@ -0,0 +1,32 @@
34+
+# Copyright 2020 The Kubernetes Authors.
35+
+
36+
+# Licensed under the Apache License, Version 2.0 (the "License");
37+
+# you may not use this file except in compliance with the License.
38+
+# You may obtain a copy of the License at
39+
+
40+
+# http://www.apache.org/licenses/LICENSE-2.0
41+
+
42+
+# Unless required by applicable law or agreed to in writing, software
43+
+# distributed under the License is distributed on an "AS IS" BASIS,
44+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45+
+# See the License for the specific language governing permissions and
46+
+# limitations under the License.
47+
+
48+
+---
49+
+- name: Get the list of installed kernels
50+
+ ansible.builtin.shell: "rpm -q kernel --qf '%{version}-%{release}\n' | sort -V"
51+
+ register: installed_kernels
52+
+
53+
+- name: Get the current running kernel
54+
+ ansible.builtin.command: "uname -r"
55+
+ register: current_kernel
56+
+
57+
+- name: Filter out the current kernels
58+
+ set_fact:
59+
+ old_kernels: "{{ installed_kernels.stdout_lines | difference([current_kernel.stdout]) |list }}"
60+
+
61+
+- name: Remove old kernels
62+
+ ansible.builtin.yum:
63+
+ name: "kernel-{{ item }}"
64+
+ state: absent
65+
+ loop: "{{ old_kernels }}"
66+
\ No newline at end of file
67+
diff --git a/images/capi/ansible/roles/setup/tasks/redhat.yml b/images/capi/ansible/roles/setup/tasks/redhat.yml
68+
index 72b7a0346..da422a10a 100644
69+
--- a/images/capi/ansible/roles/setup/tasks/redhat.yml
70+
+++ b/images/capi/ansible/roles/setup/tasks/redhat.yml
71+
@@ -110,7 +110,7 @@
72+
yum:
73+
name: '*'
74+
state: latest
75+
- exclude: kernel*,cloud-init*
76+
+ exclude: cloud-init*
77+
lock_timeout: 60
78+
79+
- name: install baseline dependencies
80+
--
81+
2.39.3 (Apple Git-145)
82+

0 commit comments

Comments
 (0)