-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Add CRD for template references
- Loading branch information
Showing
23 changed files
with
1,112 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2023. | ||
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 ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// TemplateStore holds reference to a template that can be offered as a starting point | ||
type TemplateStore struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec TemplateRef `json:"spec,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// TemplateStoreList contains a list of TemplateStore | ||
type TemplateStoreList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []TemplateStore `json:"items"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
cyclops-ctrl/config/crd/bases/cyclops-ui.com_templatestores.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.11.3 | ||
creationTimestamp: null | ||
name: templatestores.cyclops-ui.com | ||
spec: | ||
group: cyclops-ui.com | ||
names: | ||
kind: TemplateStore | ||
listKind: TemplateStoreList | ||
plural: templatestores | ||
singular: templatestore | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
description: TemplateStore holds reference to a template that can be offered | ||
as a starting point | ||
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: | ||
properties: | ||
path: | ||
type: string | ||
repo: | ||
type: string | ||
version: | ||
type: string | ||
required: | ||
- path | ||
- repo | ||
- version | ||
type: object | ||
type: object | ||
served: true | ||
storage: true |
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,31 @@ | ||
package k8sclient | ||
|
||
import ( | ||
cyclopsv1alpha1 "github.com/cyclops-ui/cycops-ctrl/api/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (k *KubernetesClient) ListTemplateStore() ([]cyclopsv1alpha1.TemplateStore, error) { | ||
return k.moduleset.TemplateStore(cyclopsNamespace).List(metav1.ListOptions{}) | ||
} | ||
|
||
func (k *KubernetesClient) CreateTemplateStore(ts *cyclopsv1alpha1.TemplateStore) error { | ||
_, err := k.moduleset.TemplateStore(cyclopsNamespace).Create(ts) | ||
return err | ||
} | ||
|
||
func (k *KubernetesClient) UpdateTemplateStore(ts *cyclopsv1alpha1.TemplateStore) error { | ||
curr, err := k.moduleset.TemplateStore(cyclopsNamespace).Get(ts.Name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ts.SetResourceVersion(curr.GetResourceVersion()) | ||
|
||
_, err = k.moduleset.TemplateStore(cyclopsNamespace).Update(ts) | ||
return err | ||
} | ||
|
||
func (k *KubernetesClient) DeleteTemplateStore(name string) error { | ||
return k.moduleset.TemplateStore(cyclopsNamespace).Delete(name) | ||
} |
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,98 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"context" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/client-go/rest" | ||
"time" | ||
|
||
cyclopsv1alpha1 "github.com/cyclops-ui/cycops-ctrl/api/v1alpha1" | ||
) | ||
|
||
type TemplateStoreInterface interface { | ||
List(opts metav1.ListOptions) ([]cyclopsv1alpha1.TemplateStore, error) | ||
Get(name string) (*cyclopsv1alpha1.TemplateStore, error) | ||
Create(*cyclopsv1alpha1.TemplateStore) (*cyclopsv1alpha1.TemplateStore, error) | ||
Update(*cyclopsv1alpha1.TemplateStore) (*cyclopsv1alpha1.TemplateStore, error) | ||
Watch(opts metav1.ListOptions) (watch.Interface, error) | ||
Delete(name string) error | ||
} | ||
|
||
type templateStoreClient struct { | ||
restClient rest.Interface | ||
ns string | ||
} | ||
|
||
func (c *templateStoreClient) List(opts metav1.ListOptions) ([]cyclopsv1alpha1.TemplateStore, error) { | ||
result := cyclopsv1alpha1.TemplateStoreList{} | ||
err := c.restClient. | ||
Get(). | ||
Namespace(c.ns). | ||
Resource("templatestores"). | ||
Do(context.Background()). | ||
Into(&result) | ||
|
||
return result.Items, err | ||
} | ||
|
||
func (c *templateStoreClient) Get(name string) (*cyclopsv1alpha1.TemplateStore, error) { | ||
result := cyclopsv1alpha1.TemplateStore{} | ||
err := c.restClient. | ||
Get(). | ||
Namespace(c.ns). | ||
Resource("templatestores"). | ||
Name(name). | ||
Do(context.Background()). | ||
Into(&result) | ||
|
||
return &result, err | ||
} | ||
|
||
func (c *templateStoreClient) Create(project *cyclopsv1alpha1.TemplateStore) (*cyclopsv1alpha1.TemplateStore, error) { | ||
result := cyclopsv1alpha1.TemplateStore{} | ||
err := c.restClient. | ||
Post(). | ||
Namespace(c.ns). | ||
Resource("templatestores"). | ||
Body(project). | ||
Do(context.Background()). | ||
Into(&result) | ||
|
||
return &result, err | ||
} | ||
|
||
func (c *templateStoreClient) Update(templateStore *cyclopsv1alpha1.TemplateStore) (project *cyclopsv1alpha1.TemplateStore, err error) { | ||
result := &cyclopsv1alpha1.TemplateStore{} | ||
err = c.restClient.Put(). | ||
Namespace(c.ns). | ||
Resource("templatestores"). | ||
Name(templateStore.Name). | ||
Body(templateStore). | ||
Do(context.TODO()). | ||
Into(result) | ||
return | ||
} | ||
|
||
func (c *templateStoreClient) Watch(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.restClient.Get(). | ||
Namespace(c.ns). | ||
Resource("templatestores"). | ||
Timeout(timeout). | ||
Watch(context.Background()) | ||
} | ||
|
||
func (c *templateStoreClient) Delete(name string) error { | ||
return c.restClient. | ||
Delete(). | ||
Namespace(c.ns). | ||
Resource("templatestores"). | ||
Name(name). | ||
Do(context.Background()). | ||
Error() | ||
} |
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
Oops, something went wrong.