Skip to content

Commit 5392de1

Browse files
committed
Add version check for machine config operator
The CNO started using machine configs from 4.15 for IPsec deployment, so adding a check for machine config operator to be at least >= 4.15 to roll out IPsec machine configs. Otherwise during OCP 4.14->4.15 upgrade, even before MCO is upgraded to 4.15, IPsec machine configs are rolled out, it uses ipsec extension from 4.14 version to install packages, installs libreswan 4.9 version on the node intermeditately. So this MCO version check ensures IPsec machine configs are rendered after MCO is upgraded to 4.15 and nodes get desired libreswan version 4.6. Signed-off-by: Periyasamy Palanisamy <[email protected]>
1 parent 865ac69 commit 5392de1

File tree

4 files changed

+77
-36
lines changed

4 files changed

+77
-36
lines changed

pkg/network/ovn_kubernetes.go

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
iputil "github.com/openshift/cluster-network-operator/pkg/util/ip"
4747
"github.com/openshift/cluster-network-operator/pkg/util/k8s"
4848
mcutil "github.com/openshift/cluster-network-operator/pkg/util/machineconfig"
49+
"github.com/openshift/cluster-network-operator/pkg/version"
4950
)
5051

5152
const CLUSTER_CONFIG_NAME = "cluster-config-v1"
@@ -598,6 +599,34 @@ func shouldRenderIPsec(conf *operv1.OVNKubernetesConfig, bootstrapResult *bootst
598599
// with the the IPsec MachineConfig extensions active, the containerized
599600
// daemonset is dormant and the host daemonset is active. When the upgrade
600601
// finishes, the containerized daemonset is then not rendered.
602+
//
603+
// The upgrade from 4.14 is handled very carefully to correctly migrate
604+
// from containerized ipsec deployment to the host ipsec deployment.
605+
// 1. OCP 4.14 with container ipsec deployment is active using libreswan
606+
// 4.6.3; and host ipsec deployment is dormant.
607+
// 2. Start the 4.15 upgrade.
608+
// 3. CNO upgrades to 4.15.
609+
// 4. CNO renders 4.15 versions of the container ipsec deployment and
610+
// host ipsec deployment with no state change. However the host ipsec
611+
// deployment mounts to top system level directories for the host ipsec
612+
// path for this upgrade scenario. It fixes two problems.
613+
// a) version mismatch between libreswan installed on the host and
614+
// host ipsec deployment pod container.
615+
// b) host ipsec deployment pod goes into pending state if we mount the
616+
// binaries directly and libreswan has not been installed yet
617+
// installed on the host by IPsec machine configs.
618+
// 5. CNO waits until MCO is upgraded to 4.15 and then deploys CNO ipsec
619+
// machine configs that will install and run libreswan 4.6.3 on the
620+
// host. Otherwise, without waiting for MCO 4.15, libreswan 4.9 may
621+
// be installed from 4.14 MCO which has all known stability problems
622+
// found from the bugs.
623+
// https://issues.redhat.com/browse/OCPBUGS-41823
624+
// https://issues.redhat.com/browse/OCPBUGS-42952
625+
// 6. Host ipsec deployment becomes active using libreswan 4.6.3 from the
626+
// container which can successfully run against libreswan 4.6.3 running
627+
// on the host.
628+
// 7. At the same time as step 6, containerized ipsec deployment becomes
629+
// dormant, and eventually gets removed when the upgrade is done.
601630

602631
isHypershiftHostedCluster := bootstrapResult.Infra.HostedControlPlane != nil
603632
isOVNIPsecActiveOrRollingOut := bootstrapResult.OVN.IPsecUpdateStatus != nil && bootstrapResult.OVN.IPsecUpdateStatus.IsOVNIPsecActiveOrRollingOut
@@ -1486,10 +1515,10 @@ func shouldUpdateOVNKonUpgrade(ovn bootstrap.OVNBootstrapResult, releaseVersion
14861515

14871516
// compute version delta
14881517
// versionUpgrade means the existing daemonSet needs an upgrade.
1489-
controlPlaneDelta := compareVersions(controlPlaneVersion, releaseVersion)
1490-
nodeDelta := compareVersions(nodeVersion, releaseVersion)
1518+
controlPlaneDelta := version.CompareVersions(controlPlaneVersion, releaseVersion)
1519+
nodeDelta := version.CompareVersions(nodeVersion, releaseVersion)
14911520

1492-
if controlPlaneDelta == versionUnknown || nodeDelta == versionUnknown {
1521+
if controlPlaneDelta == version.VersionUnknown || nodeDelta == version.VersionUnknown {
14931522
klog.Warningf("could not determine ovn-kubernetes daemonset update directions; node: %s, control-plane: %s, release: %s",
14941523
nodeVersion, controlPlaneVersion, releaseVersion)
14951524
return true, true
@@ -1513,14 +1542,14 @@ func shouldUpdateOVNKonUpgrade(ovn bootstrap.OVNBootstrapResult, releaseVersion
15131542

15141543
// both older (than CNO)
15151544
// Update node only.
1516-
if controlPlaneDelta == versionUpgrade && nodeDelta == versionUpgrade {
1545+
if controlPlaneDelta == version.VersionUpgrade && nodeDelta == version.VersionUpgrade {
15171546
klog.V(2).Infof("Upgrading OVN-Kubernetes node before control-plane")
15181547
return true, false
15191548
}
15201549

15211550
// control plane older, node updated
15221551
// update control plane if node is rolled out
1523-
if controlPlaneDelta == versionUpgrade && nodeDelta == versionSame {
1552+
if controlPlaneDelta == version.VersionUpgrade && nodeDelta == version.VersionSame {
15241553
if ovn.NodeUpdateStatus.Progressing {
15251554
klog.V(2).Infof("Waiting for OVN-Kubernetes node update to roll out before updating control-plane")
15261555
return true, false
@@ -1531,14 +1560,14 @@ func shouldUpdateOVNKonUpgrade(ovn bootstrap.OVNBootstrapResult, releaseVersion
15311560

15321561
// both newer
15331562
// downgrade control plane before node
1534-
if controlPlaneDelta == versionDowngrade && nodeDelta == versionDowngrade {
1563+
if controlPlaneDelta == version.VersionDowngrade && nodeDelta == version.VersionDowngrade {
15351564
klog.V(2).Infof("Downgrading OVN-Kubernetes control-plane before node")
15361565
return false, true
15371566
}
15381567

15391568
// control plane same, node needs downgrade
15401569
// wait for control plane rollout
1541-
if controlPlaneDelta == versionSame && nodeDelta == versionDowngrade {
1570+
if controlPlaneDelta == version.VersionSame && nodeDelta == version.VersionDowngrade {
15421571
if ovn.ControlPlaneUpdateStatus.Progressing {
15431572
klog.V(2).Infof("Waiting for OVN-Kubernetes control-plane downgrade to roll out before downgrading node")
15441573
return false, true
@@ -1548,7 +1577,7 @@ func shouldUpdateOVNKonUpgrade(ovn bootstrap.OVNBootstrapResult, releaseVersion
15481577
}
15491578

15501579
// unlikely, should be caught above
1551-
if controlPlaneDelta == versionSame && nodeDelta == versionSame {
1580+
if controlPlaneDelta == version.VersionSame && nodeDelta == version.VersionSame {
15521581
return true, true
15531582
}
15541583

@@ -1701,7 +1730,7 @@ func isOVNIPsecNotActiveInDaemonSet(ds *appsv1.DaemonSet) bool {
17011730
return false
17021731
}
17031732
// If IPsec is running with older version and ipsec=true is found from nbdb container, then return false.
1704-
if !isVersionGreaterThanOrEqualTo(annotations["release.openshift.io/version"], 4, 15) &&
1733+
if !version.IsVersionGreaterThanOrEqualTo(annotations["release.openshift.io/version"], 4, 15) &&
17051734
isIPSecEnabledInPod(ds.Spec.Template, util.OVN_NBDB) {
17061735
return false
17071736
}

pkg/platform/platform.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/openshift/cluster-network-operator/pkg/hypershift"
1313
"github.com/openshift/cluster-network-operator/pkg/names"
1414
mcutil "github.com/openshift/cluster-network-operator/pkg/util/machineconfig"
15+
"github.com/openshift/cluster-network-operator/pkg/version"
1516
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
1617
"github.com/pkg/errors"
1718
corev1 "k8s.io/api/core/v1"
@@ -234,7 +235,16 @@ func isMachineConfigClusterOperatorReady(client cnoclient.Client) (bool, error)
234235
progressing = isConditionTrue
235236
}
236237
}
237-
machineConfigClusterOperatorReady := available && !degraded && !progressing
238+
// The network operator is supporting machine configs starting with IPsec machine configs from 4.15, so
239+
// we need to consider it has to be >= 4.15 as well.
240+
var isDesiredOperatorVersion bool
241+
for _, v := range machineConfigClusterOperator.Status.Versions {
242+
if v.Name == "operator" {
243+
isDesiredOperatorVersion = version.IsVersionGreaterThanOrEqualTo(v.Version, 4, 15)
244+
break
245+
}
246+
}
247+
machineConfigClusterOperatorReady := available && !degraded && !progressing && isDesiredOperatorVersion
238248
return machineConfigClusterOperatorReady, nil
239249
}
240250

pkg/network/semver.go renamed to pkg/version/semver.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package network
1+
package version
22

33
import (
44
"github.com/Masterminds/semver"
@@ -8,49 +8,51 @@ import (
88
type versionChange int
99

1010
const (
11-
versionUpgrade versionChange = -1
12-
versionSame versionChange = 0
13-
versionDowngrade versionChange = 1
14-
versionUnknown versionChange = 2
11+
VersionUpgrade versionChange = -1
12+
VersionSame versionChange = 0
13+
VersionDowngrade versionChange = 1
14+
VersionUnknown versionChange = 2
1515
)
1616

1717
func (v versionChange) String() string {
1818
switch v {
19-
case versionUpgrade:
19+
case VersionUpgrade:
2020
return "upgrade"
21-
case versionSame:
21+
case VersionSame:
2222
return "same"
23-
case versionDowngrade:
23+
case VersionDowngrade:
2424
return "downgrade"
25-
case versionUnknown:
25+
case VersionUnknown:
2626
return "unknown"
2727
}
2828
klog.Warningf("unhandled versionChange value %d", v)
2929
return "UNHANDLED"
3030
}
3131

32-
// compareVersions compares two semver versions
32+
// CompareVersions compares two semver versions
3333
// if fromVersion is older than toVersion, returns versionOlder
3434
// likewise, if fromVersion is newer, returns versionNewer
35-
func compareVersions(fromVersion, toVersion string) versionChange {
35+
func CompareVersions(fromVersion, toVersion string) versionChange {
3636
if fromVersion == toVersion {
37-
return versionSame
37+
return VersionSame
3838
}
3939

4040
v1, err := semver.NewVersion(fromVersion)
4141
if err != nil {
42-
return versionUnknown
42+
return VersionUnknown
4343
}
4444

4545
v2, err := semver.NewVersion(toVersion)
4646
if err != nil {
47-
return versionUnknown
47+
return VersionUnknown
4848
}
4949

5050
return versionChange(v1.Compare(v2))
5151
}
5252

53-
func isVersionGreaterThanOrEqualTo(version string, major int, minor int) bool {
53+
// IsVersionGreaterThanOrEqualTo returns true if given version string
54+
// in greater than or equal to major.min version, otherwise returns false.
55+
func IsVersionGreaterThanOrEqualTo(version string, major int, minor int) bool {
5456
v, err := semver.NewVersion(version)
5557
if err != nil {
5658
klog.Errorf("failed to parse version %s: %v", version, err)

pkg/network/semver_test.go renamed to pkg/version/semver_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package network
1+
package version
22

33
import (
44
"strconv"
@@ -16,47 +16,47 @@ func TestDirection(t *testing.T) {
1616
{
1717
"1.2.3",
1818
"1.2.4",
19-
versionUpgrade,
19+
VersionUpgrade,
2020
},
2121
{
2222
"1.2.4",
2323
"1.2.3",
24-
versionDowngrade,
24+
VersionDowngrade,
2525
},
2626
{
2727
"asdf",
2828
"fdsa",
29-
versionUnknown,
29+
VersionUnknown,
3030
},
3131
{
3232
"1.1.1",
3333
"1.1.1",
34-
versionSame,
34+
VersionSame,
3535
},
3636
{
3737
"4.7.0-0.ci-2021-01-16-102811",
3838
"4.7.0-0.ci-2021-01-18-121038",
39-
versionUpgrade,
39+
VersionUpgrade,
4040
},
4141
{
4242
"4.7.0-0.ci-2021-01-18-121038",
4343
"4.7.0-0.ci-2021-01-16-102811",
44-
versionDowngrade,
44+
VersionDowngrade,
4545
},
4646
{
4747
"4.6.0-0.ci-2021-01-18-121038",
4848
"4.7.0-0.ci-2021-01-16-102811",
49-
versionUpgrade,
49+
VersionUpgrade,
5050
},
5151
{
5252
"4.6.5",
5353
"4.7.0-0.ci-2021-01-16-102811",
54-
versionUpgrade,
54+
VersionUpgrade,
5555
},
5656
} {
5757
t.Run(strconv.Itoa(idx), func(t *testing.T) {
5858
g := NewGomegaWithT(t)
59-
g.Expect(compareVersions(tc.from, tc.to)).To(Equal(tc.result))
59+
g.Expect(CompareVersions(tc.from, tc.to)).To(Equal(tc.result))
6060
})
6161
}
6262
}
@@ -102,7 +102,7 @@ func TestVersionComparison(t *testing.T) {
102102
t.Run(strconv.Itoa(idx), func(t *testing.T) {
103103
g := NewGomegaWithT(t)
104104

105-
g.Expect(isVersionGreaterThanOrEqualTo(tc.version, tc.otherVersionMajor, tc.otherVersionMinor)).To(Equal(tc.resultGreaterThanOrEqualTo))
105+
g.Expect(IsVersionGreaterThanOrEqualTo(tc.version, tc.otherVersionMajor, tc.otherVersionMinor)).To(Equal(tc.resultGreaterThanOrEqualTo))
106106
})
107107
}
108108
}

0 commit comments

Comments
 (0)