Skip to content

Commit 71cf3b4

Browse files
Merge pull request #1382 from soltysh/bump_alert_version
Update API alerts after recent bump to k8s 1.25
2 parents 9c36fe3 + 3d985c7 commit 71cf3b4

File tree

2 files changed

+56
-23
lines changed

2 files changed

+56
-23
lines changed

bindata/assets/alerts/api-usage.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
a successful upgrade to the next cluster version.
1717
Refer to `oc get apirequestcounts {{ $labels.resource }}.{{ $labels.version }}.{{ $labels.group }} -o yaml` to identify the workload.
1818
expr: |
19-
group(apiserver_requested_deprecated_apis{removed_release="1.25"}) by (group,version,resource) and (sum by(group,version,resource) (rate(apiserver_request_total{system_client!="kube-controller-manager",system_client!="cluster-policy-controller"}[4h]))) > 0
19+
group(apiserver_requested_deprecated_apis{removed_release="1.26"}) by (group,version,resource) and (sum by(group,version,resource) (rate(apiserver_request_total{system_client!="kube-controller-manager",system_client!="cluster-policy-controller"}[4h]))) > 0
2020
for: 1h
2121
labels:
2222
namespace: openshift-kube-apiserver
@@ -30,7 +30,7 @@ spec:
3030
a successful upgrade to the next EUS cluster version.
3131
Refer to `oc get apirequestcounts {{ $labels.resource }}.{{ $labels.version }}.{{ $labels.group }} -o yaml` to identify the workload.
3232
expr: |
33-
group(apiserver_requested_deprecated_apis{removed_release=~"1\\.2[5]"}) by (group,version,resource) and (sum by(group,version,resource) (rate(apiserver_request_total{system_client!="kube-controller-manager",system_client!="cluster-policy-controller"}[4h]))) > 0
33+
group(apiserver_requested_deprecated_apis{removed_release=~"1\\.2[67]"}) by (group,version,resource) and (sum by(group,version,resource) (rate(apiserver_request_total{system_client!="kube-controller-manager",system_client!="cluster-policy-controller"}[4h]))) > 0
3434
3535
for: 1h
3636
labels:

test/e2e/certrotation_test.go

+54-21
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@ package e2e
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
57
"testing"
68
"time"
79

10+
"github.com/stretchr/testify/require"
11+
12+
corev1 "k8s.io/api/core/v1"
813
"k8s.io/apimachinery/pkg/api/errors"
14+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
"k8s.io/apimachinery/pkg/util/wait"
16+
"k8s.io/client-go/kubernetes"
917

18+
configv1 "github.com/openshift/api/config/v1"
1019
operatorv1 "github.com/openshift/api/operator/v1"
1120
configclient "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
1221
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/operatorclient"
1322
test "github.com/openshift/cluster-kube-apiserver-operator/test/library"
1423
configv1helpers "github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers"
1524
"github.com/openshift/library-go/pkg/operator/genericoperatorclient"
1625
"github.com/openshift/library-go/pkg/operator/v1helpers"
17-
"github.com/stretchr/testify/require"
18-
corev1 "k8s.io/api/core/v1"
19-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20-
"k8s.io/apimachinery/pkg/util/wait"
21-
"k8s.io/client-go/kubernetes"
2226
)
2327

2428
func TestCertRotationTimeUpgradeable(t *testing.T) {
@@ -29,12 +33,13 @@ func TestCertRotationTimeUpgradeable(t *testing.T) {
2933
configClient, err := configclient.NewForConfig(kubeConfig)
3034
require.NoError(t, err)
3135

32-
ctx := context.TODO()
36+
ctx := context.Background()
3337
_, operatorStatus, _, err := operatorClient.GetStaticPodOperatorStateWithQuorum(ctx)
3438
require.NoError(t, err)
3539
require.True(t, v1helpers.IsOperatorConditionTrue(operatorStatus.Conditions, "CertRotationTimeUpgradeable"))
3640

3741
kubeClient := kubernetes.NewForConfigOrDie(kubeConfig)
42+
t.Logf("Creating unsupported-cert-rotation-config...")
3843
_, err = kubeClient.CoreV1().ConfigMaps(operatorclient.GlobalUserSpecifiedConfigNamespace).Create(context.TODO(), &corev1.ConfigMap{
3944
ObjectMeta: metav1.ObjectMeta{Namespace: operatorclient.GlobalUserSpecifiedConfigNamespace, Name: "unsupported-cert-rotation-config"},
4045
Data: map[string]string{"base": "2y"},
@@ -44,28 +49,56 @@ func TestCertRotationTimeUpgradeable(t *testing.T) {
4449
kubeClient.CoreV1().ConfigMaps(operatorclient.GlobalUserSpecifiedConfigNamespace).Delete(context.TODO(), "unsupported-cert-rotation-config", metav1.DeleteOptions{})
4550
}()
4651

47-
// TODO better detection maybe someday
48-
time.Sleep(5 * time.Second)
52+
err = wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
53+
_, operatorStatus, _, err := operatorClient.GetStaticPodOperatorStateWithQuorum(ctx)
54+
if err != nil {
55+
return false, err
56+
}
57+
clusteroperator, err := configClient.ClusterOperators().Get(context.TODO(), "kube-apiserver", metav1.GetOptions{})
58+
if err != nil {
59+
return false, err
60+
}
4961

50-
_, operatorStatus, _, err = operatorClient.GetStaticPodOperatorStateWithQuorum(ctx)
51-
require.NoError(t, err)
52-
require.True(t, v1helpers.IsOperatorConditionFalse(operatorStatus.Conditions, "CertRotationTimeUpgradeable"))
53-
clusteroperator, err := configClient.ClusterOperators().Get(context.TODO(), "kube-apiserver", metav1.GetOptions{})
62+
certRotationCondition := v1helpers.FindOperatorCondition(operatorStatus.Conditions, "CertRotationTimeUpgradeable")
63+
upgradeableCondition := configv1helpers.FindStatusCondition(clusteroperator.Status.Conditions, "Upgradeable")
64+
if certRotationCondition == nil || upgradeableCondition == nil {
65+
return false, fmt.Errorf("Couldn't find CertRotationTimeUpgradeable or Upgradeable condition")
66+
}
67+
if certRotationCondition.Status == operatorv1.ConditionFalse &&
68+
upgradeableCondition.Status == configv1.ConditionFalse && strings.Contains(upgradeableCondition.Reason, "CertRotationTime") {
69+
return true, nil
70+
}
71+
t.Logf("\nCertRotationTimeUpgradeable: %#v\nUpgradeable: %#v", certRotationCondition, upgradeableCondition)
72+
return false, nil
73+
})
5474
require.NoError(t, err)
55-
require.True(t, configv1helpers.IsStatusConditionFalse(clusteroperator.Status.Conditions, "Upgradeable"))
5675

76+
t.Logf("Removing unsupported-cert-rotation-config...")
5777
err = kubeClient.CoreV1().ConfigMaps(operatorclient.GlobalUserSpecifiedConfigNamespace).Delete(context.TODO(), "unsupported-cert-rotation-config", metav1.DeleteOptions{})
5878
require.NoError(t, err)
59-
// TODO better detection maybe someday
60-
time.Sleep(5 * time.Second)
6179

62-
_, operatorStatus, _, err = operatorClient.GetStaticPodOperatorStateWithQuorum(ctx)
63-
require.NoError(t, err)
64-
require.True(t, v1helpers.IsOperatorConditionTrue(operatorStatus.Conditions, "CertRotationTimeUpgradeable"))
65-
clusteroperator, err = configClient.ClusterOperators().Get(context.TODO(), "kube-apiserver", metav1.GetOptions{})
80+
err = wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
81+
_, operatorStatus, _, err := operatorClient.GetStaticPodOperatorStateWithQuorum(ctx)
82+
if err != nil {
83+
return false, err
84+
}
85+
clusteroperator, err := configClient.ClusterOperators().Get(context.TODO(), "kube-apiserver", metav1.GetOptions{})
86+
if err != nil {
87+
return false, err
88+
}
89+
certRotationCondition := v1helpers.FindOperatorCondition(operatorStatus.Conditions, "CertRotationTimeUpgradeable")
90+
upgradeableCondition := configv1helpers.FindStatusCondition(clusteroperator.Status.Conditions, "Upgradeable")
91+
if certRotationCondition == nil || upgradeableCondition == nil {
92+
return false, fmt.Errorf("Couldn't find CertRotationTimeUpgradeable or Upgradeable condition")
93+
}
94+
if certRotationCondition.Status == operatorv1.ConditionTrue &&
95+
(upgradeableCondition.Status == configv1.ConditionTrue || !strings.Contains(upgradeableCondition.Reason, "CertRotationTime")) {
96+
return true, nil
97+
}
98+
t.Logf("\nCertRotationTimeUpgradeable: %#v\nUpgradeable: %#v", certRotationCondition, upgradeableCondition)
99+
return false, nil
100+
})
66101
require.NoError(t, err)
67-
require.True(t, configv1helpers.IsStatusConditionTrue(clusteroperator.Status.Conditions, "Upgradeable"))
68-
69102
}
70103

71104
func TestCertRotationStompOnBadType(t *testing.T) {

0 commit comments

Comments
 (0)