-
Notifications
You must be signed in to change notification settings - Fork 250
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
Add Namespace Check to Task Delete Command #350
Merged
tekton-robot
merged 1 commit into
tektoncd:master
from
danielhelfand:namespace_err_delete
Oct 10, 2019
Merged
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
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
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,32 @@ | ||
// Copyright © 2019 The Tekton Authors. | ||
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. Idea here would be to use this class for common validation methods across the CLI. |
||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package validate | ||
|
||
import ( | ||
k8s "k8s.io/client-go/kubernetes" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// Check if namespace exists. Returns error if namespace specified with -n doesn't exist or if user doesn't have permissions to view. | ||
func NamespaceExists(kube k8s.Interface, ns string) error { | ||
|
||
_, err := kube.CoreV1().Namespaces().Get(ns, metav1.GetOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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,54 @@ | ||
// Copyright © 2019 The Tekton Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package validate | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tektoncd/cli/pkg/test" | ||
pipelinetest "github.com/tektoncd/pipeline/test" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestNamespaceExists_Invalid_Namespace(t *testing.T) { | ||
ns := []*corev1.Namespace{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "default", | ||
}, | ||
}, | ||
} | ||
cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) | ||
p := &test.Params{Kube: cs.Kube} | ||
|
||
err := NamespaceExists(p.Kube, "foo") | ||
test.AssertOutput(t, "namespaces \"foo\" not found", err.Error()) | ||
} | ||
|
||
func TestNamespaceExists_Valid_Namespace(t *testing.T) { | ||
ns := []*corev1.Namespace{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "default", | ||
}, | ||
}, | ||
} | ||
cs, _ := test.SeedTestData(t, pipelinetest.Data{Namespaces: ns}) | ||
p := &test.Params{Kube: cs.Kube} | ||
|
||
err := NamespaceExists(p.Kube, "default") | ||
test.AssertOutput(t, nil, err) | ||
} |
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.
If there's a way to avoid the second error check here, would be nice. Was originally passing the clients as a param to
printTaskDetails
, but I'm not opposed to two checks.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.
Agree, I was also thinking of
where
validate.KubeClient(p)
returns avalidator function
like:func validator() error
andvalidate.All
just checks none of the functions return an error`That way all commands would just have to invoke just
WDYT?
BTW, I am not suggesting this change in this PR :)
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.
Sure, I think that's really clever. I'll keep this in mind a try to refactor it.