Skip to content

Commit a3d5290

Browse files
author
Artyom Lukianov
committed
e2e upgrade: wait for other components to handle PAO resources updates
It possible that the PAO will need to update KubeletConfig, MachineConfig or Tuned profiles after the upgrade, in this case we should wait until relevant controllers will finish work to update nodes with relevant changes. Signed-off-by: Artyom Lukianov <[email protected]>
1 parent 142534b commit a3d5290

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

functests-extended/1_performance_operator_upgrade/upgrade_operator.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ import (
66
"fmt"
77
"time"
88

9+
"github.com/openshift-kni/performance-addon-operators/functests/utils/tuned"
10+
911
. "github.com/onsi/ginkgo"
1012
. "github.com/onsi/gomega"
13+
machineconfigv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
1114
olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
12-
13-
v1 "k8s.io/api/core/v1"
15+
corev1 "k8s.io/api/core/v1"
1416
"k8s.io/apimachinery/pkg/types"
1517
"sigs.k8s.io/controller-runtime/pkg/client"
1618

19+
performancev2 "github.com/openshift-kni/performance-addon-operators/api/v2"
20+
testutils "github.com/openshift-kni/performance-addon-operators/functests/utils"
1721
testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client"
22+
"github.com/openshift-kni/performance-addon-operators/functests/utils/mcps"
1823
"github.com/openshift-kni/performance-addon-operators/functests/utils/namespaces"
24+
"github.com/openshift-kni/performance-addon-operators/functests/utils/nodes"
25+
"github.com/openshift-kni/performance-addon-operators/functests/utils/profiles"
1926
)
2027

2128
var fromVersion string
@@ -29,13 +36,28 @@ func init() {
2936
}
3037

3138
var _ = Describe("[rfe_id:28567][performance] Performance Addon Operator Upgrades", func() {
39+
var performanceProfile *performancev2.PerformanceProfile
40+
var performanceMCP string
41+
var workerRTNodes []corev1.Node
3242

33-
BeforeEach(func() {
43+
testutils.BeforeAll(func() {
3444
subscriptionsList := &olmv1alpha1.SubscriptionList{}
3545
err := testclient.Client.List(context.TODO(), subscriptionsList, &client.ListOptions{Namespace: namespaces.PerformanceOperator})
3646
ExpectWithOffset(1, err).ToNot(HaveOccurred(), "Failed getting Subscriptions")
3747
Expect(len(subscriptionsList.Items)).To(Equal(1), fmt.Sprintf("Unexpected number of Subscriptions found: %v", len(subscriptionsList.Items)))
3848
subscription = &subscriptionsList.Items[0]
49+
50+
workerRTNodes, err = nodes.GetByLabels(testutils.NodeSelectorLabels)
51+
Expect(err).ToNot(HaveOccurred())
52+
workerRTNodes, err = nodes.MatchingOptionalSelector(workerRTNodes)
53+
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("error looking for the optional selector: %v", err))
54+
Expect(workerRTNodes).ToNot(BeEmpty(), "cannot find RT enabled worker nodes")
55+
56+
nodeLabel := testutils.NodeSelectorLabels
57+
performanceProfile, err = profiles.GetByNodeLabels(nodeLabel)
58+
Expect(err).ToNot(HaveOccurred())
59+
performanceMCP, err = mcps.GetByProfile(performanceProfile)
60+
Expect(err).ToNot(HaveOccurred())
3961
})
4062

4163
It("[test_id:30876] upgrades performance profile operator", func() {
@@ -73,7 +95,7 @@ var _ = Describe("[rfe_id:28567][performance] Performance Addon Operator Upgrade
7395
// the W/A deletes OLM related pods to initiate OLM pods restart
7496
By("Getting OLM pods")
7597
for _, labelValue := range []string{"olm-operator", "catalog-operator"} {
76-
olmPods := &v1.PodList{}
98+
olmPods := &corev1.PodList{}
7799
Expect(testclient.Client.List(
78100
context.TODO(),
79101
olmPods,
@@ -95,6 +117,18 @@ var _ = Describe("[rfe_id:28567][performance] Performance Addon Operator Upgrade
95117
csv = getCSV(subscription.Status.CurrentCSV, namespaces.PerformanceOperator)
96118
csvWaitForPhaseWithConditionReason(csv.Name, namespaces.PerformanceOperator, olmv1alpha1.CSVPhaseSucceeded, olmv1alpha1.CSVReasonInstallSuccessful)
97119
Expect(csv.ObjectMeta.Annotations["containerImage"]).NotTo(Equal(fromImage))
120+
121+
// it is impossible to predict if it was some changes under generated by PAO KubeletConfig or Tuned
122+
// during the PAO upgrade, so the best we can do here is to wait some time,
123+
// to give other controllers time to notify changes
124+
time.Sleep(2 * time.Minute)
125+
mcps.WaitForCondition(performanceMCP, machineconfigv1.MachineConfigPoolUpdated, corev1.ConditionTrue)
126+
127+
var workerRTNodesNames []string
128+
for _, workerRTNode := range workerRTNodes {
129+
workerRTNodesNames = append(workerRTNodesNames, workerRTNode.Name)
130+
}
131+
Expect(tuned.WaitForAppliedCondition(workerRTNodesNames, corev1.ConditionTrue, 5*time.Minute))
98132
})
99133
})
100134

functests/utils/tuned/tuned.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package tuned
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
9+
corev1 "k8s.io/api/core/v1"
10+
"k8s.io/apimachinery/pkg/types"
11+
"k8s.io/apimachinery/pkg/util/wait"
12+
"k8s.io/klog"
13+
14+
testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client"
15+
"github.com/openshift-kni/performance-addon-operators/pkg/controller/performanceprofile/components"
16+
)
17+
18+
func WaitForAppliedCondition(tunedProfileNames []string, conditionStatus corev1.ConditionStatus, timeout time.Duration) error {
19+
return wait.PollImmediate(time.Second, timeout, func() (bool, error) {
20+
for _, tunedProfileName := range tunedProfileNames {
21+
profile := &tunedv1.Profile{}
22+
key := types.NamespacedName{
23+
Name: tunedProfileName,
24+
Namespace: components.NamespaceNodeTuningOperator,
25+
}
26+
27+
if err := testclient.Client.Get(context.TODO(), key, profile); err != nil {
28+
klog.Errorf("failed to get tuned profile %q: %v", tunedProfileName, err)
29+
return false, nil
30+
}
31+
32+
appliedCondition, err := GetConditionByType(profile.Status.Conditions, tunedv1.TunedProfileApplied)
33+
if err != nil {
34+
klog.Errorf("failed to get applied condition for profile %q: %v", tunedProfileName, err)
35+
return false, nil
36+
}
37+
38+
if appliedCondition.Status != conditionStatus {
39+
return false, nil
40+
}
41+
}
42+
43+
return true, nil
44+
})
45+
}
46+
47+
func GetConditionByType(conditions []tunedv1.ProfileStatusCondition, conditionType tunedv1.ProfileConditionType) (*tunedv1.ProfileStatusCondition, error) {
48+
for i := range conditions {
49+
c := &conditions[i]
50+
if c.Type == conditionType {
51+
return c, nil
52+
}
53+
}
54+
return nil, fmt.Errorf("failed to found applied condition under conditions %v", conditions)
55+
}

0 commit comments

Comments
 (0)