Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTA-1301: WIP: pkg/cincinnati: Set DifferentChannel risk #1059

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/cincinnati/cincinnati.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/url"
"slices"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -236,14 +237,33 @@ func (c Client) GetUpdates(ctx context.Context, uri *url.URL, desiredArch, curre
}
}

for i, conditionalUpdate := range conditionalUpdates {
if !slices.Contains(conditionalUpdate.Release.Channels, channel) {
conditionalUpdates[i].Risks = append(conditionalUpdate.Risks, differentChannelRisk(conditionalUpdate.Release, channel))
}
}

for i := len(updates) - 1; i >= 0; i-- {
dropped := false
for _, conditionalUpdate := range conditionalUpdates {
if conditionalUpdate.Release.Image == updates[i].Image {
klog.Warningf("Update to %s listed as both a conditional and unconditional update; preferring the conditional update.", conditionalUpdate.Release.Version)
updates = append(updates[:i], updates[i+1:]...)
dropped = true
break
}
}
if dropped {
continue
}

if !slices.Contains(updates[i].Channels, channel) {
conditionalUpdates = append(conditionalUpdates, configv1.ConditionalUpdate{
Release: updates[i],
Risks: []configv1.ConditionalUpdateRisk{differentChannelRisk(updates[i], channel)},
})
updates = append(updates[:i], updates[i+1:]...)
}
}

if len(updates) == 0 {
Expand Down Expand Up @@ -346,3 +366,12 @@ func convertRetrievedUpdateToRelease(update node) (configv1.Release, error) {
}
return cvoUpdate, nil
}

func differentChannelRisk(release configv1.Release, channel string) configv1.ConditionalUpdateRisk {
return configv1.ConditionalUpdateRisk{
Name: "DifferentChannel",
URL: "https://example.com/FIXME", // Maybe a KCS? New doc section that we think might be stable between 4.y? Other?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bit that needs figuring out still

Message: fmt.Sprintf("%s channels (%s) do not include this cluster's %s", release.Version, strings.Join(release.Channels, ", "), channel),
MatchingRules: []configv1.ClusterCondition{{Type: "Always"}},
}
}
15 changes: 10 additions & 5 deletions pkg/cvo/availableupdates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ func (n notFoundConfigMapLister) Get(name string) (*corev1.ConfigMap, error) {
func osusWithSingleConditionalEdge() (*httptest.Server, clusterconditions.Condition, []configv1.ConditionalUpdate, string) {
from := "4.5.5"
to := "4.5.6"
channel := "channel"
osus := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{
"nodes": [{"version": "%s", "payload": "payload/%s"}, {"version": "%s", "payload": "payload/%s"}],
"nodes": [
{"version": "%s", "payload": "payload/%s", "metadata": {"io.openshift.upgrades.graph.release.channels": "%s"}},
{"version": "%s", "payload": "payload/%s", "metadata": {"io.openshift.upgrades.graph.release.channels": "%s"}}
],
"conditionalEdges": [
{
"edges": [{"from": "%s", "to": "%s"}],
Expand All @@ -72,12 +76,12 @@ func osusWithSingleConditionalEdge() (*httptest.Server, clusterconditions.Condit
}
]
}
`, from, from, to, to, from, to, to)
`, from, from, channel, to, to, channel, from, to, to)
}))

updates := []configv1.ConditionalUpdate{
{
Release: configv1.Release{Version: to, Image: "payload/" + to},
Release: configv1.Release{Version: to, Image: "payload/" + to, Channels: []string{channel}},
Risks: []configv1.ConditionalUpdateRisk{
{
URL: "https://example.com/" + to,
Expand Down Expand Up @@ -111,7 +115,8 @@ func osusWithSingleConditionalEdge() (*httptest.Server, clusterconditions.Condit
}

func newOperator(url, version string, promqlMock clusterconditions.Condition) (*availableUpdates, *Operator) {
currentRelease := configv1.Release{Version: version, Image: "payload/" + version}
channel := "channel"
currentRelease := configv1.Release{Version: version, Image: "payload/" + version, Channels: []string{channel}}
registry := clusterconditions.NewConditionRegistry()
registry.Register("Always", &always.Always{})
registry.Register("PromQL", promqlMock)
Expand All @@ -126,7 +131,7 @@ func newOperator(url, version string, promqlMock clusterconditions.Condition) (*
}
availableUpdates := &availableUpdates{
Architecture: "amd64",
Current: configv1.Release{Version: version, Image: "payload/" + version},
Current: configv1.Release{Version: version, Image: "payload/" + version, Channels: []string{channel}},
}
return availableUpdates, operator
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cvo/cvo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2614,9 +2614,9 @@ func TestOperator_availableUpdatesSync(t *testing.T) {
fmt.Fprintf(w, `
{
"nodes": [
{"version":"4.0.1", "payload": "image/image:v4.0.1"},
{"version":"4.0.2-prerelease", "payload": "some.other.registry/image/image:v4.0.2"},
{"version":"4.0.2", "payload": "image/image:v4.0.2"}
{"version":"4.0.1", "payload": "image/image:v4.0.1", "metadata": {"io.openshift.upgrades.graph.release.channels": "fast"}},
{"version":"4.0.2-prerelease", "payload": "some.other.registry/image/image:v4.0.2", "metadata": {"io.openshift.upgrades.graph.release.channels": "fast"}},
{"version":"4.0.2", "payload": "image/image:v4.0.2", "metadata": {"io.openshift.upgrades.graph.release.channels": "fast"}}
],
"edges": [
[0, 1],
Expand Down Expand Up @@ -2663,10 +2663,10 @@ func TestOperator_availableUpdatesSync(t *testing.T) {
UpdateService: "http://localhost:8080/graph",
Channel: "fast",
Architecture: "amd64",
Current: configv1.Release{Version: "4.0.1", Image: "image/image:v4.0.1"},
Current: configv1.Release{Version: "4.0.1", Image: "image/image:v4.0.1", Channels: []string{"fast"}},
Updates: []configv1.Release{
{Version: "4.0.2", Image: "image/image:v4.0.2"},
{Version: "4.0.2-prerelease", Image: "some.other.registry/image/image:v4.0.2"},
{Version: "4.0.2", Image: "image/image:v4.0.2", Channels: []string{"fast"}},
{Version: "4.0.2-prerelease", Image: "some.other.registry/image/image:v4.0.2", Channels: []string{"fast"}},
},
Condition: configv1.ClusterOperatorStatusCondition{
Type: configv1.RetrievedUpdates,
Expand Down