Skip to content

Commit

Permalink
Merge pull request #143 from coryodaniel/fix-v1-api-crd
Browse files Browse the repository at this point in the history
Fix CRD apiextensions.k8s.io/v1 generation refs #117, #101
  • Loading branch information
Michael Ruoss authored Aug 31, 2022
2 parents d152439 + 56041c3 commit 0b39a9d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 36 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## Updated
### Updated

- Use name of application in Deployments instead of service account name. ([#142](https://github.com/coryodaniel/bonny/pull/142))

### Fixed

- Use name of application in Deployments instead of service account name.
- CRD manifest generation for `apiextensions.k8s.io/v1` ([#143](https://github.com/coryodaniel/bonny/pull/143), [#117](https://github.com/coryodaniel/bonny/issues/117), [#101](https://github.com/coryodaniel/bonny/pull/101))

## [0.5.1] - 2022-05-25

Expand Down
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ if Mix.env() == :test do
http_provider: K8s.Client.DynamicHTTPProvider

config :bonny,
controllers: [Widget, Cog],
controllers: [Widget, Cog, Whizbang],
group: "example.com",
get_conn: {Bonny.K8sMock, :conn},
api_version: "apiextensions.k8s.io/v1beta1"
api_version: "apiextensions.k8s.io/v1"
end

if Mix.env() == :dev do
Expand Down
12 changes: 8 additions & 4 deletions lib/bonny/crd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ defmodule Bonny.CRD do
|> Map.put(:versions, [
%{
name: version,
scheme: %{
openAPIV3Scheme: %{
additionalPrinterColumns: additional_printer_columns_v1
served: true,
storage: true,
schema: %{
openAPIV3Schema: %{
type: "object",
"x-kubernetes-preserve-unknown-fields": true
}
}
},
additionalPrinterColumns: additional_printer_columns_v1
}
])
end
Expand Down
30 changes: 17 additions & 13 deletions test/bonny/crd_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,24 @@ defmodule Bonny.CRDTest do
versions: [
%{
name: "v1",
scheme: %{
openAPIV3Scheme: %{
additionalPrinterColumns: [
%{jsonPath: ".spec.test", description: "test", name: "test", type: "string"},
%{
jsonPath: ".metadata.creationTimestamp",
description:
"CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.\n\n Populated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata",
name: "Age",
type: "date"
}
]
served: true,
storage: true,
schema: %{
openAPIV3Schema: %{
type: "object",
"x-kubernetes-preserve-unknown-fields": true
}
}
},
additionalPrinterColumns: [
%{jsonPath: ".spec.test", description: "test", name: "test", type: "string"},
%{
jsonPath: ".metadata.creationTimestamp",
description:
"CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.\n\n Populated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata",
name: "Age",
type: "date"
}
]
}
]
}
Expand Down
71 changes: 56 additions & 15 deletions test/bonny/operator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Bonny.OperatorTest do
},
%{apiGroups: ["example.com"], resources: ["widgets"], verbs: ["*"]},
%{apiGroups: ["example.com"], resources: ["cogs"], verbs: ["*"]},
%{apiGroups: ["example.com"], resources: ["whizbangs"], verbs: ["*"]},
%{apiGroups: ["apps"], resources: ["deployments", "services"], verbs: ["*"]},
%{apiGroups: [""], resources: ["configmaps"], verbs: ["create", "read"]}
]
Expand All @@ -37,6 +38,7 @@ defmodule Bonny.OperatorTest do
},
%{apiGroups: ["example.com"], resources: ["widgets"], verbs: ["*"]},
%{apiGroups: ["example.com"], resources: ["cogs"], verbs: ["*"]},
%{apiGroups: ["example.com"], resources: ["whizbangs"], verbs: ["*"]},
%{apiGroups: ["apps"], resources: ["deployments", "services"], verbs: ["*"]},
%{apiGroups: [""], resources: ["configmaps"], verbs: ["create", "read"]}
]
Expand All @@ -61,36 +63,75 @@ defmodule Bonny.OperatorTest do

expected = [
%{
apiVersion: "apiextensions.k8s.io/v1beta1",
apiVersion: "apiextensions.k8s.io/v1",
kind: "CustomResourceDefinition",
metadata: %{labels: %{"k8s-app" => "bonny"}, name: "widgets.example.com"},
spec: %{
additionalPrinterColumns: [
%{JSONPath: ".spec.test", description: "test", name: "test", type: "string"},
%{
JSONPath: ".metadata.creationTimestamp",
description:
"CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.\n\n Populated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata",
name: "Age",
type: "date"
}
],
group: "example.com",
names: %{kind: "Widget", plural: "widgets", shortNames: nil, singular: "widget"},
scope: "Namespaced",
version: "v1"
versions: [
%{
additionalPrinterColumns: [
%{description: "test", jsonPath: ".spec.test", name: "test", type: "string"},
%{
description:
"CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.\n\n Populated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata",
jsonPath: ".metadata.creationTimestamp",
name: "Age",
type: "date"
}
],
name: "v1",
schema: %{
openAPIV3Schema: %{type: "object", "x-kubernetes-preserve-unknown-fields": true}
},
served: true,
storage: true
}
]
}
},
%{
apiVersion: "apiextensions.k8s.io/v1beta1",
apiVersion: "apiextensions.k8s.io/v1",
kind: "CustomResourceDefinition",
metadata: %{labels: %{"k8s-app" => "bonny"}, name: "cogs.example.com"},
spec: %{
additionalPrinterColumns: [],
group: "example.com",
names: %{kind: "Cog", plural: "cogs", shortNames: nil, singular: "cog"},
scope: "Namespaced",
version: "v1"
versions: [
%{
additionalPrinterColumns: [],
name: "v1",
schema: %{
openAPIV3Schema: %{type: "object", "x-kubernetes-preserve-unknown-fields": true}
},
served: true,
storage: true
}
]
}
},
%{
apiVersion: "apiextensions.k8s.io/v1",
kind: "CustomResourceDefinition",
metadata: %{labels: %{"k8s-app" => "bonny"}, name: "whizbangs.example.com"},
spec: %{
group: "example.com",
names: %{kind: "Whizbang", plural: "whizbangs", shortNames: nil, singular: "whizbang"},
scope: "Namespaced",
versions: [
%{
additionalPrinterColumns: [],
name: "v1",
schema: %{
openAPIV3Schema: %{type: "object", "x-kubernetes-preserve-unknown-fields": true}
},
served: true,
storage: true
}
]
}
}
]
Expand Down

0 comments on commit 0b39a9d

Please sign in to comment.