Skip to content

Commit

Permalink
update CRD to apiextensions.k8s.io/v1
Browse files Browse the repository at this point in the history
  • Loading branch information
abursavich committed Aug 23, 2020
1 parent f5ba683 commit 8f7a5cb
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 135 deletions.
15 changes: 14 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [ConfigMapSecretSpec](#configmapsecretspec)
* [ConfigMapSecretStatus](#configmapsecretstatus)
* [ConfigMapTemplate](#configmaptemplate)
* [TemplateMetadata](#templatemetadata)
* [TemplateVariable](#templatevariable)

## ConfigMapSecret
Expand Down Expand Up @@ -87,12 +88,24 @@ ConfigMapTemplate is a ConfigMap template.

| Field | Description | Type | Required |
| ----- | ----------- | ---- | -------- |
| metadata | Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata | [metav1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta) | false |
| metadata | Metadata is a stripped down version of the standard object metadata. Its properties will be applied to the metadata of the generated Secret. If no name is provided, the name of the ConfigMapSecret will be used. | [TemplateMetadata](#templatemetadata) | false |
| data | Data contains the configuration data. Each key must consist of alphanumeric characters, '-', '_' or '.'. Values with non-UTF-8 byte sequences must use the BinaryData field. The keys stored in Data must not overlap with the keys in the BinaryData field. | map[string]string | false |
| binaryData | BinaryData contains the binary data. Each key must consist of alphanumeric characters, '-', '_' or '.'. BinaryData can contain byte sequences that are not in the UTF-8 range. The keys stored in BinaryData must not overlap with the keys in the Data field. | map[string][]byte | false |

[Back to TOC](#table-of-contents)

## TemplateMetadata

TemplateMetadata is a stripped down version of the standard object metadata.

| Field | Description | Type | Required |
| ----- | ----------- | ---- | -------- |
| name | Name must be unique within a namespace. Is required when creating resources, although some resources may allow a client to request the generation of an appropriate name automatically. Name is primarily intended for creation idempotence and configuration definition. More info: http://kubernetes.io/docs/user-guide/identifiers#names | string | false |
| labels | Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels | map[string]string | false |
| annotations | Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects. More info: http://kubernetes.io/docs/user-guide/annotations | map[string]string | false |

[Back to TOC](#table-of-contents)

## TemplateVariable

TemplateVariable is a template variable.
Expand Down
2 changes: 1 addition & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func generateCode() error {
}

func generateCDRs() error {
out, err := sh.Output("controller-gen", "crd:trivialVersions=true", "paths=./pkg/...", "output:stdout")
out, err := sh.Output("controller-gen", "crd:crdVersions=v1", "paths=./pkg/...", "output:stdout")
if err != nil {
return err
}
Expand Down
250 changes: 133 additions & 117 deletions manifest/customresourcedefinition.yaml

Large diffs are not rendered by default.

40 changes: 34 additions & 6 deletions pkg/api/v1alpha1/configmapsecret_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ type ConfigMapSecretSpec struct {

// ConfigMapTemplate is a ConfigMap template.
type ConfigMapTemplate struct {
// Standard object metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// Metadata is a stripped down version of the standard object metadata.
// Its properties will be applied to the metadata of the generated Secret.
// If no name is provided, the name of the ConfigMapSecret will be used.
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
Metadata TemplateMetadata `json:"metadata,omitempty"`

// Data contains the configuration data.
// Each key must consist of alphanumeric characters, '-', '_' or '.'.
Expand All @@ -87,6 +88,31 @@ type ConfigMapTemplate struct {
BinaryData map[string][]byte `json:"binaryData,omitempty"`
}

// TemplateMetadata is a stripped down version of the standard object metadata.
type TemplateMetadata struct {
// Name must be unique within a namespace. Is required when creating resources, although
// some resources may allow a client to request the generation of an appropriate name
// automatically. Name is primarily intended for creation idempotence and configuration
// definition.
// More info: http://kubernetes.io/docs/user-guide/identifiers#names
// +optional
Name string `json:"name,omitempty"`

// Map of string keys and values that can be used to organize and categorize
// (scope and select) objects. May match selectors of replication controllers
// and services.
// More info: http://kubernetes.io/docs/user-guide/labels
// +optional
Labels map[string]string `json:"labels,omitempty"`

// Annotations is an unstructured key value map stored with a resource that may be
// set by external tools to store and retrieve arbitrary metadata. They are not
// queryable and should be preserved when modifying objects.
// More info: http://kubernetes.io/docs/user-guide/annotations
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
}

// TemplateVariable is a template variable.
type TemplateVariable struct {
// Name of the template variable.
Expand Down Expand Up @@ -115,9 +141,11 @@ type ConfigMapSecretStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Represents the latest available observations of a ConfigMapSecret's current state.
// +patchMergeKey=type
// +patchStrategy=merge
Conditions []ConfigMapSecretCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
// +listType=map
// +listMapKey=type
// +listMapKeys=type
// +optional
Conditions []ConfigMapSecretCondition `json:"conditions,omitempty"`
}

// ConfigMapSecretCondition describes the state of a ConfigMapSecret.
Expand Down
31 changes: 30 additions & 1 deletion pkg/api/v1alpha1/zz_generated.deepcopy.go

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

9 changes: 5 additions & 4 deletions pkg/controllers/configmapsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (r *ConfigMapSecret) Reconcile(req reconcile.Request) (reconcile.Result, er
}

func (r *ConfigMapSecret) cleanup(ctx context.Context, log logr.Logger, cms *v1alpha1.ConfigMapSecret) error {
secretName := cms.Spec.Template.Name
secretName := cms.Spec.Template.Metadata.Name
if secretName == "" {
secretName = cms.Name
}
Expand Down Expand Up @@ -331,16 +331,17 @@ func (r *ConfigMapSecret) renderSecret(ctx context.Context, cms *v1alpha1.Config
data[k] = []byte(expansion.Expand(string(v), varMapFn))
}

name := cms.Spec.Template.Name
meta := cms.Spec.Template.Metadata
name := meta.Name
if name == "" {
name = cms.Name
}
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: cms.Namespace,
Labels: cms.Spec.Template.Labels,
Annotations: cms.Spec.Template.Annotations,
Labels: meta.Labels,
Annotations: meta.Annotations,
},
Data: data,
Type: corev1.SecretTypeOpaque,
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/configmapsecret_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestReconciler(t *testing.T) {
},
Spec: v1alpha1.ConfigMapSecretSpec{
Template: v1alpha1.ConfigMapTemplate{
ObjectMeta: metav1.ObjectMeta{
Metadata: v1alpha1.TemplateMetadata{
Labels: map[string]string{
"foo": "bar",
},
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestReconciler(t *testing.T) {
Namespace: "default",
},
func(obj *v1alpha1.ConfigMapSecret) {
obj.Spec.Template.ObjectMeta = metav1.ObjectMeta{
obj.Spec.Template.Metadata = v1alpha1.TemplateMetadata{
Labels: map[string]string{
"foo": "abc",
"bar": "xyz",
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestReconciler(t *testing.T) {
},
Spec: v1alpha1.ConfigMapSecretSpec{
Template: v1alpha1.ConfigMapTemplate{
ObjectMeta: metav1.ObjectMeta{
Metadata: v1alpha1.TemplateMetadata{
Annotations: map[string]string{
"foo": "bar",
},
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestReconciler(t *testing.T) {
Namespace: "default",
},
func(obj *v1alpha1.ConfigMapSecret) {
obj.Spec.Template.ObjectMeta = metav1.ObjectMeta{
obj.Spec.Template.Metadata = v1alpha1.TemplateMetadata{
Annotations: map[string]string{
"foo": "abc",
"bar": "xyz",
Expand Down
4 changes: 3 additions & 1 deletion pkg/controllers/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func TestMain(m *testing.M) {
check(clientscheme.AddToScheme(scheme))
check(v1alpha1.AddToScheme(scheme))
testenv := &envtest.Environment{
CRDDirectoryPaths: []string{"../../manifest"},
CRDInstallOptions: envtest.CRDInstallOptions{
Paths: []string{"../../manifest"},
},
}
var err error
cfg, err = testenv.Start()
Expand Down

0 comments on commit 8f7a5cb

Please sign in to comment.