-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix cardtemplate resolve status, rename samples
- Loading branch information
Showing
12 changed files
with
262 additions
and
54 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,170 @@ | ||
package columns | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/krateoplatformops/krateo-bff/apis" | ||
"github.com/krateoplatformops/krateo-bff/apis/ui/columns/v1alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
const ( | ||
resourceName = "columns" | ||
) | ||
|
||
func NewClient(rc *rest.Config) (*Client, error) { | ||
s := runtime.NewScheme() | ||
apis.AddToScheme(s) | ||
|
||
config := *rc | ||
config.APIPath = "/apis" | ||
config.GroupVersion = &schema.GroupVersion{ | ||
Group: v1alpha1.Group, Version: v1alpha1.Version, | ||
} | ||
config.NegotiatedSerializer = serializer.NewCodecFactory(s). | ||
WithoutConversion() | ||
config.UserAgent = rest.DefaultKubernetesUserAgent() | ||
|
||
cli, err := rest.RESTClientFor(&config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pc := runtime.NewParameterCodec(s) | ||
|
||
return &Client{rc: cli, pc: pc}, nil | ||
} | ||
|
||
type Client struct { | ||
rc rest.Interface | ||
pc runtime.ParameterCodec | ||
ns string | ||
} | ||
|
||
func (c *Client) Namespace(ns string) *Client { | ||
c.ns = ns | ||
return c | ||
} | ||
|
||
func (c *Client) Get(ctx context.Context, name string) (result *v1alpha1.Column, err error) { | ||
result = &v1alpha1.Column{} | ||
err = c.rc.Get(). | ||
Namespace(c.ns). | ||
Resource(resourceName). | ||
Name(name). | ||
Do(ctx). | ||
Into(result) | ||
// issue: https://github.com/kubernetes/client-go/issues/541 | ||
result.SetGroupVersionKind(v1alpha1.ColumnGroupVersionKind) | ||
return | ||
} | ||
|
||
func (c *Client) List(ctx context.Context, opts metav1.ListOptions) (result *v1alpha1.ColumnList, err error) { | ||
var timeout time.Duration | ||
if opts.TimeoutSeconds != nil { | ||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second | ||
} | ||
result = &v1alpha1.ColumnList{} | ||
err = c.rc.Get(). | ||
Namespace(c.ns). | ||
Resource(resourceName). | ||
VersionedParams(&opts, c.pc). | ||
Timeout(timeout). | ||
Do(ctx). | ||
Into(result) | ||
|
||
result.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("List")) | ||
return | ||
} | ||
|
||
func (c *Client) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { | ||
var timeout time.Duration | ||
if opts.TimeoutSeconds != nil { | ||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second | ||
} | ||
opts.Watch = true | ||
return c.rc.Get(). | ||
Namespace(c.ns). | ||
Resource(resourceName). | ||
VersionedParams(&opts, c.pc). | ||
Timeout(timeout). | ||
Watch(ctx) | ||
} | ||
|
||
func (c *Client) Create(ctx context.Context, obj *v1alpha1.Column, opts metav1.CreateOptions) (result *v1alpha1.Column, err error) { | ||
result = &v1alpha1.Column{} | ||
err = c.rc.Post(). | ||
Namespace(c.ns). | ||
Resource(resourceName). | ||
VersionedParams(&opts, c.pc). | ||
Body(obj). | ||
Do(ctx). | ||
Into(result) | ||
// issue: https://github.com/kubernetes/client-go/issues/541 | ||
result.SetGroupVersionKind(v1alpha1.ColumnGroupVersionKind) | ||
return | ||
} | ||
|
||
func (c *Client) Update(ctx context.Context, obj *v1alpha1.Column, opts metav1.UpdateOptions) (result *v1alpha1.Column, err error) { | ||
result = &v1alpha1.Column{} | ||
err = c.rc.Put(). | ||
Namespace(c.ns). | ||
Resource(resourceName). | ||
Name(obj.Name). | ||
VersionedParams(&opts, c.pc). | ||
Body(obj). | ||
Do(ctx). | ||
Into(result) | ||
// issue: https://github.com/kubernetes/client-go/issues/541 | ||
result.SetGroupVersionKind(v1alpha1.ColumnGroupVersionKind) | ||
return | ||
} | ||
|
||
func (c *Client) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { | ||
return c.rc.Delete(). | ||
Namespace(c.ns). | ||
Resource(resourceName). | ||
Name(name). | ||
Body(&opts). | ||
Do(ctx). | ||
Error() | ||
} | ||
|
||
func (c *Client) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { | ||
var timeout time.Duration | ||
if listOpts.TimeoutSeconds != nil { | ||
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second | ||
} | ||
return c.rc.Delete(). | ||
Namespace(c.ns). | ||
Resource(resourceName). | ||
VersionedParams(&listOpts, c.pc). | ||
Timeout(timeout). | ||
Body(&opts). | ||
Do(ctx). | ||
Error() | ||
} | ||
|
||
func (c *Client) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1alpha1.Column, err error) { | ||
result = &v1alpha1.Column{} | ||
err = c.rc.Patch(pt). | ||
Namespace(c.ns). | ||
Resource(resourceName). | ||
Name(name). | ||
SubResource(subresources...). | ||
VersionedParams(&opts, c.pc). | ||
Body(data). | ||
Do(ctx). | ||
Into(result) | ||
// issue: https://github.com/kubernetes/client-go/issues/541 | ||
result.SetGroupVersionKind(v1alpha1.ColumnGroupVersionKind) | ||
return | ||
} |
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,77 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package columns_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/krateoplatformops/krateo-bff/internal/kubernetes/layout/columns" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
const ( | ||
namespace = "dev-system" | ||
name = "sample" | ||
) | ||
|
||
func TestColumnGet(t *testing.T) { | ||
cfg, err := newRestConfig() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
cli, err := columns.NewClient(cfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
res, err := cli.Namespace(namespace).Get(context.TODO(), name) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
enc := json.NewEncoder(os.Stdout) | ||
enc.SetIndent("", " ") | ||
if err := enc.Encode(res); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestColumnList(t *testing.T) { | ||
cfg, err := newRestConfig() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
cli, err := columns.NewClient(cfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
all, err := cli.Namespace(namespace).List(context.TODO(), v1.ListOptions{}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
enc := json.NewEncoder(os.Stdout) | ||
enc.SetIndent("", " ") | ||
if err := enc.Encode(all); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func newRestConfig() (*rest.Config, error) { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return clientcmd.BuildConfigFromFlags("", filepath.Join(home, ".kube", "config")) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
|
||
kubectl apply -f crds/ | ||
kubectl apply -f testdata/cardtemplate-dev.yaml | ||
kubectl apply -f testdata/cardtemplate-sample.yaml |
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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