Skip to content

Commit

Permalink
Clean yum caches when configuring repos (#3146)
Browse files Browse the repository at this point in the history
* Clean yum caches when configuring repos

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

* Update fixtures

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>

---------

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
  • Loading branch information
xmudrii authored Apr 16, 2024
1 parent 56dcd13 commit c7014ab
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 221 deletions.
18 changes: 5 additions & 13 deletions pkg/scripts/os_amzn.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf
{{ if .CONFIGURE_REPOSITORIES }}
# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false
if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -62,10 +53,11 @@ gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/{{ .KUBERNETES_MAJOR_MINOR }}/rpm/repodata/repomd.xml.key
EOF
if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache
{{ end }}
sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/os_centos.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf
{{ if .CONFIGURE_REPOSITORIES }}
# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false
if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -68,10 +59,11 @@ if [ "$ID" == "centos" ] && [ "$VERSION_ID" == "8" ]; then
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
fi
if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache
{{ end }}
sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-force.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -71,10 +62,11 @@ gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -71,10 +62,11 @@ gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-proxy.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -71,10 +62,11 @@ gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-v1.26.0.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -71,10 +62,11 @@ gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-with_cilium.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -71,10 +62,11 @@ gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-with_containerd.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -71,10 +62,11 @@ gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -71,10 +62,11 @@ gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/testdata/TestKubeadmCentOS-cilium_cluster.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -77,10 +68,11 @@ if [ "$ID" == "centos" ] && [ "$VERSION_ID" == "8" ]; then
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
fi

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/testdata/TestKubeadmCentOS-nutanix_cluster.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -77,10 +68,11 @@ if [ "$ID" == "centos" ] && [ "$VERSION_ID" == "8" ]; then
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
fi

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
18 changes: 5 additions & 13 deletions pkg/scripts/testdata/TestKubeadmCentOS-with_containerd.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
Expand All @@ -77,10 +68,11 @@ if [ "$ID" == "centos" ] && [ "$VERSION_ID" == "8" ]; then
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
fi

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
# We must clean 'yum' cache upon changing the package repository
# because older 'yum' versions (e.g. CentOS and Amazon Linux 2)
# don't detect the change otherwise.
sudo yum clean all
sudo yum makecache


sudo yum install -y \
Expand Down
Loading

0 comments on commit c7014ab

Please sign in to comment.