Skip to content

Commit 8f28014

Browse files
committed
fix(adm-upgrade): switched to checking for CVO in alerts(). Wrote unit test for new functions
Signed-off-by: Nick Bottari <nbottari9@gmail.com> fix(alerts): prevent duplication of warnings by disabling client-side alert checking if the server is already doing it. Signed-off-by: Nick Bottari <nbottari@nbottari-thinkpadp1gen4i.boston.csb> fix(adm-upgrade): changed method of detecting if CVO is already checking alerts Signed-off-by: Nick Bottari <nbottari9@gmail.com> fix(adm-upgrade): add check for hypershift and improve error checking Signed-off-by: Nick Bottari <nbottari9@gmail.com> fix(adm-upgrade): switched to checking for CVO in alerts(). Wrote unit test for new functions Signed-off-by: Nick Bottari <nbottari9@gmail.com>
1 parent 9557cf3 commit 8f28014

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

pkg/cli/admin/upgrade/recommend/alerts.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"strings"
88

9+
configv1 "github.com/openshift/api/config/v1"
10+
"github.com/openshift/api/features"
911
routev1 "github.com/openshift/api/route/v1"
1012
routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
1113
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -20,6 +22,19 @@ import (
2022
// and Unknown when we do not have enough information to make a
2123
// happy-or-sad determination.
2224
func (o *options) alerts(ctx context.Context) ([]acceptableCondition, error) {
25+
26+
if o.Client != nil {
27+
featureGates, _ := o.Client.ConfigV1().FeatureGates().Get(ctx, "cluster", metav1.GetOptions{})
28+
infrastructure, _ := o.Client.ConfigV1().Infrastructures().Get(ctx, "cluster", metav1.GetOptions{})
29+
cv, _ := o.Client.ConfigV1().ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
30+
31+
// if the AcceptRisks feature gate AND hypershift is not enabled,
32+
// the CVO is handling alerts and will generate the Recommended condition if needed
33+
if cv == nil && isAcceptRisksEnabled(featureGates, cv.Status.Desired.Version) && !isHypershiftEnabled(infrastructure) {
34+
return nil, nil
35+
}
36+
}
37+
2338
var alertsBytes []byte
2439
if o.mockData.alertsPath != "" {
2540
if len(o.mockData.alerts) == 0 {
@@ -251,3 +266,30 @@ func (o *options) alerts(ctx context.Context) ([]acceptableCondition, error) {
251266

252267
return conditions, nil
253268
}
269+
270+
// isAcceptRisksEnabled checks to see if the 'ClusterUpdateAcceptRisks' feature gate is enabled
271+
// if so, return true to skip client-side alert checking
272+
func isAcceptRisksEnabled(featureGate *configv1.FeatureGate, clusterVersion string) bool {
273+
if featureGate == nil {
274+
return false
275+
}
276+
277+
for _, versionedGates := range featureGate.Status.FeatureGates {
278+
if versionedGates.Version == clusterVersion {
279+
for _, enabledGate := range versionedGates.Enabled {
280+
if enabledGate.Name == features.FeatureGateClusterUpdateAcceptRisks {
281+
return true
282+
}
283+
}
284+
}
285+
}
286+
return false
287+
}
288+
289+
func isHypershiftEnabled(i *configv1.Infrastructure) bool {
290+
if i == nil {
291+
return false
292+
}
293+
294+
return i.Status.ControlPlaneTopology == configv1.ExternalTopologyMode
295+
}

pkg/cli/admin/upgrade/recommend/recommend.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ func (o *options) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string
132132
o.version = &version
133133
}
134134
}
135-
136135
return nil
137136
}
138137

pkg/cli/admin/upgrade/recommend/recommend_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
configv1 "github.com/openshift/api/config/v1"
9+
"github.com/openshift/api/features"
910
)
1011

1112
func TestSortConditionalUpdatesBySemanticVersions(t *testing.T) {
@@ -29,3 +30,38 @@ func TestSortConditionalUpdatesBySemanticVersions(t *testing.T) {
2930
t.Errorf("%v != %v", actual, expected)
3031
}
3132
}
33+
34+
func TestIsAcceptRisksEnabled(t *testing.T) {
35+
featureGate := &configv1.FeatureGate{
36+
Status: configv1.FeatureGateStatus{
37+
FeatureGates: []configv1.FeatureGateDetails{
38+
{
39+
Version: "4.22.0",
40+
Enabled: []configv1.FeatureGateAttributes{
41+
{
42+
Name: features.FeatureGateClusterUpdateAcceptRisks,
43+
},
44+
},
45+
},
46+
},
47+
},
48+
}
49+
50+
result := isAcceptRisksEnabled(featureGate, "4.22.0")
51+
if result != true {
52+
t.Errorf("ClusterUpdateAcceptRisks feature gate should report as enabled")
53+
}
54+
}
55+
56+
func TestIsHypershiftEnabled(t *testing.T) {
57+
infra := &configv1.Infrastructure{
58+
Status: configv1.InfrastructureStatus{
59+
ControlPlaneTopology: configv1.ExternalTopologyMode,
60+
},
61+
}
62+
63+
result := isHypershiftEnabled(infra)
64+
if result != true {
65+
t.Errorf("Hypershift should report as enabled")
66+
}
67+
}

0 commit comments

Comments
 (0)