Skip to content

Commit

Permalink
convert gvk to gvr (knative#192)
Browse files Browse the repository at this point in the history
Co-authored-by: jjzhang <jjzhang@alauda.io>
  • Loading branch information
NigelZHANG and jjzhang authored Mar 31, 2022
1 parent eb7ad3f commit fb53968
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
30 changes: 30 additions & 0 deletions errors/conver_resource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2021 The Katanomi 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 errors

import (
"testing"

"github.com/katanomi/pkg/apis/meta/v1alpha1"
. "github.com/onsi/gomega"
)

func TestGVKToGR(t *testing.T) {
projectGVK := v1alpha1.ProjectGVK
projectGVR := GVKToGVR(projectGVK)
Equal(projectGVK.Kind).Match(projectGVR.Resource)
}
29 changes: 29 additions & 0 deletions errors/convert_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2021 The Katanomi 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 errors

import "k8s.io/apimachinery/pkg/runtime/schema"

// GVKToGR convert schema GroupVersionKind to GroupVersionResource
// Warning: this function just for show error info
func GVKToGVR(gvk schema.GroupVersionKind) (gr schema.GroupVersionResource) {
return schema.GroupVersionResource{
Group: gvk.Group,
Version: gvk.Version,
Resource: gvk.Kind,
}
}

0 comments on commit fb53968

Please sign in to comment.