Skip to content

Commit 7fd7f9e

Browse files
Improve descriptions. Add "done" boolean field.
1 parent 4f41df8 commit 7fd7f9e

File tree

3 files changed

+106
-17
lines changed

3 files changed

+106
-17
lines changed

controller/homepage.tmpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
border-color: #3e8ed0 transparent #3e8ed0 transparent;
2828
animation: lds-hourglass 1.2s infinite;
2929
}
30+
31+
ul > li > span {
32+
font-style: italic;
33+
}
34+
3035
@keyframes lds-hourglass {
3136
0% {
3237
transform: rotate(0);
@@ -82,7 +87,7 @@
8287
<h3>My TODO items for namespace: {{ namespace }}</h3>
8388
<ul>
8489
<li v-for="item in items" :key="item.title">
85-
{{ item }}
90+
{{ item.name }} <span v-if="item.done">(completed)</span> <span v-else>(not completed)</span>
8691
</li>
8792
<li v-if="items.length === 0"><em>No items found</em></li>
8893
</ul>

controller/main.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,23 @@ func showTodosForNamespace(kubeApi, namespace, token string) func(http.ResponseW
8686
}
8787
}
8888

89+
type todoItem struct {
90+
Name string `json:"name"`
91+
Done bool `json:"done"`
92+
}
93+
8994
type todoData struct {
9095
Items []struct {
91-
Spec struct {
92-
Name string `json:"name"`
93-
} `json:"spec"`
96+
Spec todoItem `json:"spec"`
9497
}
9598
}
9699

97-
func specToMap(items todoData) []string {
98-
m := make([]string, 0, len(items.Items))
99-
for _, v := range items.Items {
100-
m = append(m, v.Spec.Name)
100+
func specToMap(items todoData) []todoItem {
101+
var result []todoItem
102+
103+
for _, item := range items.Items {
104+
result = append(result, item.Spec)
101105
}
102-
return m
106+
107+
return result
103108
}

kubernetes/crd.yaml

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,63 @@ kind: CustomResourceDefinition
33
metadata:
44
name: todos.patrickdap.com
55
spec:
6+
# Whether the resource is Namespaced or Cluster-wide
7+
scope: Namespaced
8+
9+
# Define all the names used by the resource, in this case
10+
# you can do:
11+
# kubectl get todos
12+
# kubectl get td
13+
names:
14+
plural: todos
15+
singular: todo
16+
kind: Todo
17+
shortNames:
18+
- td
19+
20+
# Once the resource is part of Kubernetes, it also needs a group
21+
# so then you could have foo.example.com register the concept of "Node"
22+
# as well as v1/Node (the default Kubernetes one)
623
group: patrickdap.com
24+
25+
# There's multiple versions for a Kubernetes resource, and it's common
26+
# to find "v1beta1", "v1beta2", "v1" and so on
727
versions:
8-
- name: v1
28+
-
29+
# Versions are string-based and they're prioritized based on the
30+
# Kubernetes version sorting algorithm. Those versions that match
31+
# the Kubernetes sorting are "higher versions" than those who don't.
32+
# See: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#version-priority
33+
name: v1
34+
35+
# The next two fields control the behaviour of the resource in Kubernetes.
36+
# If a resource is marked as "served", it means users can perform CRUD
37+
# operations in resources under this version, "v1" in our case, and have
38+
# them work as you would normally do.
39+
# On multiple versions, only one can be marked as "storage". This means
40+
# that the version marked as storage will be used to "store" it in etcd.
41+
# However, there's a few caveats. For example, resources created on an
42+
# older version which, back then, it was marked as "storage" will be kept
43+
# stored as their old version, and they *will not be converted* to newer
44+
# versions.
45+
# You can use a conversion webhook to "migrate" resources to newer versions
46+
# (see below for more details) or, if you manually edit the resource, you
47+
# will be able to upgrade it as well.
948
served: true
1049
storage: true
50+
deprecated: false
51+
52+
# The OpenAPI Schema used to create the resource. There's hundreds of
53+
# options here, like specifying default values, provide definitions,
54+
# define fields that depend on each other, provide descriptions for
55+
# documentation (such as "kubectl explain ..."), configure the value to
56+
# be an enum, provide a basic format validator that supports, among other
57+
# things fields like bson object IDs, uuids, isbn, credit card numbers,
58+
# US SSN, hexadecimal, rgb, byte data, passwords, dates, durations; or
59+
# you can even create sub-objects in an object, allow for patterns,
60+
# validate minimum and maximum length, whether it's nullable or required,
61+
# a title (used when printing), if the fields are unique, and a plethora
62+
# of other options.
1163
schema:
1264
openAPIV3Schema:
1365
type: object
@@ -23,10 +75,37 @@ spec:
2375
properties:
2476
name:
2577
type: string
26-
scope: Namespaced
27-
names:
28-
plural: todos
29-
singular: todo
30-
kind: Todo
31-
shortNames:
32-
- td
78+
done:
79+
type: boolean
80+
default: false
81+
82+
# When printing fields using "kubectl get foo", only the name and the age,
83+
# that is, the time since its creation, will be printed to screen. This
84+
# setting allows the creation of multiple new columns for your CRD which
85+
# will then be outputted automatically. This must match the current
86+
# top-of-the-line version for your CRD.
87+
additionalPrinterColumns:
88+
- name: Action
89+
type: string
90+
description: Indicates the action to be done
91+
jsonPath: .spec.name
92+
- name: Done
93+
type: boolean
94+
description: Indicate whether the action described by this TODO was done
95+
jsonPath: .spec.done
96+
- name: Age
97+
type: date
98+
jsonPath: .metadata.creationTimestamp
99+
100+
# Different versions might require "changes" to move values between one
101+
# version declaration to another. For example, in v1beta1, the field "foo"
102+
# could've been in spec.fields.foo, but in v1 it could've been promoted
103+
# to spec.foo (skipping "fields"). This conversion is not automated and,
104+
# by default, Kubernetes will set the conversion strategy to None.
105+
# Like Admission Controllers, it's possible to create a "webhook conversion"
106+
# which registers an endpoint in the cluster -- this can be either an
107+
# actual endpoint or a Kubernetes Service. The webhook must return a
108+
# Kubernetes "ConversionReview" response.
109+
# See: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#webhook-request-and-response
110+
conversion:
111+
strategy: None

0 commit comments

Comments
 (0)