Skip to content

Commit

Permalink
Fix cluster profile api
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 16, 2024
1 parent 77c0815 commit 44112f0
Show file tree
Hide file tree
Showing 12 changed files with 392 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/monitoring-agent-api v0.30.2-0.20241001043315-b98120efea48
kmodules.xyz/offshoot-api v0.30.1
kmodules.xyz/resource-metadata v0.19.1-0.20241016073336-1307639922b4
kmodules.xyz/resource-metadata v0.19.1-0.20241016154015-205ef283ba59
kmodules.xyz/resource-metrics v0.30.4
kmodules.xyz/resource-metrics/utils v0.30.4
kmodules.xyz/sets v0.29.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,8 @@ kmodules.xyz/monitoring-agent-api v0.30.2-0.20241001043315-b98120efea48 h1:kJdO7
kmodules.xyz/monitoring-agent-api v0.30.2-0.20241001043315-b98120efea48/go.mod h1:oR3tk5O4koYar4cD9N3AjbBFr9XTwBU3sw9qD2NdNQc=
kmodules.xyz/offshoot-api v0.30.1 h1:TrulAYO+oBsXe9sZZGTmNWIuI8qD2izMpgcTSPvgAmI=
kmodules.xyz/offshoot-api v0.30.1/go.mod h1:T3mpjR6fui0QzOcmQvIuANytW48fe9ytmy/1cgx6D4g=
kmodules.xyz/resource-metadata v0.19.1-0.20241016073336-1307639922b4 h1:k8JQX4XDUU/ULvscjx5ENBb4qNJdWFMcf2V79c+LIcI=
kmodules.xyz/resource-metadata v0.19.1-0.20241016073336-1307639922b4/go.mod h1:ZVjgAj622Fp+8bdmAgHv6PNQHkXXqhR6aQpJg3lO8Bo=
kmodules.xyz/resource-metadata v0.19.1-0.20241016154015-205ef283ba59 h1:0gErwOLp26ErRgl1K91e0MD+k+NRfp4gCTEDArQyTEM=
kmodules.xyz/resource-metadata v0.19.1-0.20241016154015-205ef283ba59/go.mod h1:ZVjgAj622Fp+8bdmAgHv6PNQHkXXqhR6aQpJg3lO8Bo=
kmodules.xyz/resource-metrics v0.30.4 h1:8HBPtYmo9ETY91gsc55JE8Z986+3ZuRq57M0wZ9npqI=
kmodules.xyz/resource-metrics v0.30.4/go.mod h1:w9+rz7/s/kGP1GWzYSuRdCn+l7EwpesmESSEHkLBnIQ=
kmodules.xyz/resource-metrics/utils v0.30.4 h1:bJS/x0Qr7N1FFdxugFbzZ/Es6HVs4ptsFlhkmgj3jac=
Expand Down
23 changes: 15 additions & 8 deletions pkg/registry/meta/clusterprofile/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/registry/rest"
"kmodules.xyz/resource-metadata/apis/meta"
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1"
"kmodules.xyz/resource-metadata/hub/clusterprofiles"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -53,14 +54,14 @@ func NewStorage(kc client.Reader) *Storage {
return &Storage{
kc: kc,
convertor: rest.NewDefaultTableConvertor(schema.GroupResource{
Group: uiapi.SchemeGroupVersion.Group,
Group: rsapi.SchemeGroupVersion.Group,
Resource: uiapi.ResourceClusterProfiles,
}),
}
}

func (r *Storage) GroupVersionKind(_ schema.GroupVersion) schema.GroupVersionKind {
return uiapi.SchemeGroupVersion.WithKind(uiapi.ResourceKindClusterProfile)
return rsapi.SchemeGroupVersion.WithKind(uiapi.ResourceKindClusterProfile)
}

func (r *Storage) NamespaceScoped() bool {
Expand All @@ -73,7 +74,7 @@ func (r *Storage) GetSingularName() string {

// Getter
func (r *Storage) New() runtime.Object {
return &uiapi.ClusterProfile{}
return &rsapi.ClusterProfile{}
}

func (r *Storage) Destroy() {}
Expand All @@ -83,12 +84,15 @@ func (r *Storage) Get(ctx context.Context, name string, options *metav1.GetOptio
if err != nil {
return nil, kerr.NewNotFound(schema.GroupResource{Group: meta.GroupName, Resource: uiapi.ResourceKindClusterProfile}, name)
}
return obj, err
return &rsapi.ClusterProfile{
ObjectMeta: obj.ObjectMeta,
Spec: obj.Spec,
}, err
}

// Lister
func (r *Storage) NewList() runtime.Object {
return &uiapi.ClusterProfileList{}
return &rsapi.ClusterProfileList{}
}

func (r *Storage) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) {
Expand All @@ -114,15 +118,18 @@ func (r *Storage) List(ctx context.Context, options *metainternalversion.ListOpt
objs = objs[:options.Limit]
}

items := make([]uiapi.ClusterProfile, 0, len(objs))
items := make([]rsapi.ClusterProfile, 0, len(objs))
for _, obj := range objs {
if options.LabelSelector != nil && !options.LabelSelector.Matches(labels.Set(obj.GetLabels())) {
continue
}
items = append(items, obj)
items = append(items, rsapi.ClusterProfile{
ObjectMeta: obj.ObjectMeta,
Spec: obj.Spec,
})
}

return &uiapi.ClusterProfileList{Items: items}, nil
return &rsapi.ClusterProfileList{Items: items}, nil
}

func (r *Storage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright AppsCode Inc. and Contributors
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 v1alpha1

import (
uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +genclient:nonNamespaced
// +genclient:skipVerbs=updateStatus
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type ClusterProfile struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec uiapi.ClusterProfileSpec `json:"spec,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

type ClusterProfileList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterProfile `json:"items,omitempty"`
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func Resource(resource string) schema.GroupResource {
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ChartPresetQuery{},
&ClusterProfile{},
&ClusterProfileList{},
&ClusterStatus{},
&ResourceCalculator{},
&ResourceDescriptor{},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
name: clusterprofiles.meta.k8s.appscode.com
spec:
group: meta.k8s.appscode.com
names:
kind: ClusterProfile
listKind: ClusterProfileList
plural: clusterprofiles
singular: clusterprofile
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .status.phase
name: Status
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ClusterProfileSpec defines the desired state of ClusterProfile
properties:
description:
type: string
provider:
type: string
requiredFeatureSets:
additionalProperties:
items:
type: string
type: array
type: object
title:
type: string
required:
- description
- title
type: object
type: object
served: true
storage: true
subresources:
status: {}
Loading

0 comments on commit 44112f0

Please sign in to comment.