-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ignore DeploymentConfig warning on oc status
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
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
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 | ||
} |