-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support providing k8s native resource through --objects flag in kanctl (
#638) * Support providing k8s native resource through --objects flag in kanctl command, while creating actionset. For ex ``` kanctl create actionset \ --action backup \ --namespace kanister \ --blueprint etcd-blueprint \ --objects /v1/pods/kube-system/etcd-minikube \ --profile kube-system/s3-profile-xhgl9 ``` * Use format v1/resources/namespace/name to provide resources from core api group * Add test for parseGenericObjectRef * Fix golint Co-authored-by: Pavan Navarathna <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
dd80704
commit 54ea015
Showing
2 changed files
with
81 additions
and
3 deletions.
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,78 @@ | ||
// Copyright 2020 The Kanister 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 kanctl | ||
|
||
import ( | ||
"testing" | ||
|
||
. "gopkg.in/check.v1" | ||
|
||
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1" | ||
) | ||
|
||
type KanctlTestSuite struct{} | ||
|
||
var _ = Suite(&KanctlTestSuite{}) | ||
|
||
func Test(t *testing.T) { TestingT(t) } | ||
|
||
func (k *KanctlTestSuite) TestParseGenericObjectReference(c *C) { | ||
for _, tc := range []struct { | ||
objectFlag string | ||
expected crv1alpha1.ObjectReference | ||
err Checker | ||
}{ | ||
// not core group | ||
{ | ||
objectFlag: "apps/v1/deployments/namespace/name", | ||
expected: crv1alpha1.ObjectReference{ | ||
APIVersion: "v1", | ||
Group: "apps/", | ||
Resource: "deployments", | ||
Name: "name", | ||
Namespace: "namespace", | ||
}, | ||
err: IsNil, | ||
}, | ||
// core group | ||
{ | ||
objectFlag: "v1/pods/kube-system/etcd-minikube ", | ||
expected: crv1alpha1.ObjectReference{ | ||
APIVersion: "v1", | ||
Group: "", | ||
Resource: "pods", | ||
Name: "etcd-minikube", | ||
Namespace: "kube-system", | ||
}, | ||
err: IsNil, | ||
}, | ||
// CRs | ||
{ | ||
objectFlag: "cr.kanister.io/v1alpha1/profiles/kanister/s3-profile-5fx9w", | ||
expected: crv1alpha1.ObjectReference{ | ||
APIVersion: "v1alpha1", | ||
Group: "cr.kanister.io/", | ||
Resource: "profiles", | ||
Name: "s3-profile-5fx9w", | ||
Namespace: "kanister", | ||
}, | ||
err: IsNil, | ||
}, | ||
} { | ||
a, err := parseGenericObjectReference(tc.objectFlag) | ||
c.Check(err, tc.err) | ||
c.Assert(a, DeepEquals, tc.expected) | ||
} | ||
} |