-
Notifications
You must be signed in to change notification settings - Fork 377
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
OCPBUGS-16418: Show more clear info about the DeploymentConfig is deprecated #1795
Open
sanchezl
wants to merge
1
commit into
openshift:master
Choose a base branch
from
sanchezl:OCPBUGS-16418
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,15 @@ package cli | |
import ( | ||
"flag" | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
"runtime" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
"github.com/openshift/oc/pkg/helpers/apps" | ||
"github.com/spf13/cobra" | ||
|
||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/cli-runtime/pkg/genericiooptions" | ||
"k8s.io/client-go/rest" | ||
|
@@ -176,8 +178,19 @@ func NewOcCommand(o kubecmd.KubectlOptions) *cobra.Command { | |
Long: cliLong, | ||
Run: runHelp, | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
rest.SetDefaultWarningHandler(warningHandler) | ||
|
||
switch cmd.Name() { | ||
case "status": | ||
rest.SetDefaultWarningHandler(apps.NewIgnoreDeploymentConfigWarningHandler(warningHandler)) | ||
case "get": | ||
if slices.ContainsFunc(args, func(s string) bool { return slices.Contains(strings.Split(s, ","), "all") }) { | ||
rest.SetDefaultWarningHandler(apps.NewIgnoreDeploymentConfigWarningHandler(warningHandler)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this will work because as we concluded that builder does not take custom warning handler into account kubernetes/kubectl#1586 (comment) and |
||
} else { | ||
rest.SetDefaultWarningHandler(warningHandler) | ||
} | ||
default: | ||
rest.SetDefaultWarningHandler(warningHandler) | ||
} | ||
slog.Info("PersistentPreRunE", "name", cmd.Name(), "calledAs", cmd.CalledAs(), "args", args) | ||
if cmd.Name() == cobra.ShellCompRequestCmd { | ||
// This is the __complete or __completeNoDesc command which | ||
// indicates shell completion has been requested. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package apps | ||
|
||
import ( | ||
"strings" | ||
|
||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type ignoreDeploymentConfigWarningHandler struct { | ||
handler rest.WarningHandler | ||
} | ||
|
||
func NewIgnoreDeploymentConfigWarningHandler(handler rest.WarningHandler) rest.WarningHandler { | ||
return &ignoreDeploymentConfigWarningHandler{handler: handler} | ||
} | ||
|
||
func (h *ignoreDeploymentConfigWarningHandler) HandleWarningHeader(code int, agent string, text string) { | ||
if h.handler == nil || strings.Contains(text, `apps.openshift.io/v1 DeploymentConfig is deprecated`) { | ||
return | ||
} | ||
h.handler.HandleWarningHeader(code, agent, text) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package apps | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestHandleWarningHeader(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
text string | ||
wraps bool | ||
expectOutput bool | ||
}{ | ||
{ | ||
name: "deprecated old", | ||
text: `apps.openshift.io/v1 DeploymentConfig is deprecated in v4.14+, unavailable in v4.10000+`, | ||
wraps: true, | ||
expectOutput: false, | ||
}, | ||
{ | ||
name: "deprecated new", | ||
text: `apps.openshift.io/v1 DeploymentConfig is deprecated in v1.27+`, | ||
wraps: true, | ||
expectOutput: false, | ||
}, | ||
{ | ||
name: "do not panic no match", | ||
text: `something else`, | ||
}, | ||
{ | ||
name: "do not panic match", | ||
text: `apps.openshift.io/v1 DeploymentConfig is deprecated in v1.27+`, | ||
wraps: false, | ||
}, | ||
{ | ||
name: "not deprecation warning", | ||
text: `DeploymentConfig is not deprecated`, | ||
wraps: true, | ||
expectOutput: true, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
var wrappedHandler mockWarningHandler | ||
if tc.wraps { | ||
wrappedHandler = mockWarningHandler{} | ||
} | ||
h := NewIgnoreDeploymentConfigWarningHandler(&wrappedHandler) | ||
h.HandleWarningHeader(http.StatusOK, "agent", tc.text) | ||
if tc.wraps { | ||
if tc.expectOutput != wrappedHandler.invoked { | ||
t.Fatalf("Wrapped hander: invoke expected: %v, invoke actual: %v", tc.expectOutput, wrappedHandler.invoked) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
type mockWarningHandler struct { | ||
invoked bool | ||
} | ||
|
||
func (m *mockWarningHandler) HandleWarningHeader(warnStatusCode int, header string, text string) { | ||
m.invoked = true | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd not prefer modifying this core cli entrance point just to update the warning text.