Skip to content

Commit 23eda62

Browse files
authored
Fix log rotation in UBI images (#6052)
logrotate needs to run as the same user as OVS to get the proper permissions for log files. As Antrea runs OVS as root, we disable libcapng to make logrotate also run as root. Fixes: #6046 Signed-off-by: Xu Liu <[email protected]>
1 parent 17ff95a commit 23eda62

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

build/images/ovs/Dockerfile.ubi

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ RUN cd /tmp/openvswitch* && \
3232
sed -e "s/@VERSION@/$OVS_VERSION/" rhel/openvswitch-fedora.spec.in > /tmp/ovs.spec && \
3333
yum-builddep -y /tmp/ovs.spec && ./boot.sh && \
3434
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc && \
35-
make rpm-fedora && mkdir -p /tmp/ovs-rpms && \
35+
# logrotate needs to run as the same user as OVS to get the proper permissions of log files.
36+
# As Antrea runs OVS as root, we disable libcapng to make logrotate also run as root.
37+
# See https://github.com/openvswitch/ovs/blob/v2.17.7/rhel/openvswitch-fedora.spec.in#L26-L27.
38+
RPMBUILD_OPT="--without libcapng" make rpm-fedora && mkdir -p /tmp/ovs-rpms && \
3639
mv /tmp/openvswitch-$OVS_VERSION/rpm/rpmbuild/RPMS/*/*.rpm /tmp/ovs-rpms && \
3740
rm -rf /tmp/openvswitch*
3841

test/e2e/basic_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestBasic(t *testing.T) {
5656
t.Run("testDeletePreviousRoundFlowsOnStartup", func(t *testing.T) { testDeletePreviousRoundFlowsOnStartup(t, data) })
5757
t.Run("testGratuitousARP", func(t *testing.T) { testGratuitousARP(t, data, data.testNamespace) })
5858
t.Run("testClusterIdentity", func(t *testing.T) { testClusterIdentity(t, data) })
59+
t.Run("testLogRotate", func(t *testing.T) { testLogRotate(t, data) })
5960
}
6061

6162
// testPodAssignIP verifies that Antrea allocates IP addresses properly to new Pods. It does this by
@@ -892,3 +893,14 @@ func testClusterIdentity(t *testing.T, data *TestData) {
892893
assert.NoError(t, err, "Failed to retrieve cluster identity information within %v", timeout)
893894
assert.NotEqual(t, uuid.Nil, clusterUUID)
894895
}
896+
897+
func testLogRotate(t *testing.T, data *TestData) {
898+
nodeName := nodeName(0)
899+
podName := getAntreaPodName(t, data, nodeName)
900+
cmd := []string{"logrotate", "-vf", "/etc/logrotate.d/openvswitch-switch"}
901+
stdout, stderr, err := data.RunCommandFromPod(antreaNamespace, podName, ovsContainerName, cmd)
902+
if err != nil {
903+
t.Fatalf("Error when running logrotate command in Pod '%s': %v, stdout: %s, stderr: %s", podName, err, stdout, stderr)
904+
}
905+
t.Logf("Successfully ran logrotate command in Pod '%s': stdout: %s, stderr: %s", podName, stdout, stderr)
906+
}

0 commit comments

Comments
 (0)