Skip to content

Commit 544ceb7

Browse files
authored
Merge pull request #3 from maiqueb/add-status-subresource
crd: add status sub resource
2 parents 0496941 + 845b64a commit 544ceb7

File tree

6 files changed

+79
-13
lines changed

6 files changed

+79
-13
lines changed

artifacts/k8s.cni.cncf.io_ipamleases.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,27 @@ spec:
3737
description: The pod interface name for which this allocation was
3838
created
3939
type: string
40+
network:
41+
description: The network attachment definition name for which this
42+
persistent allocation was created
43+
type: string
44+
required:
45+
- interface
46+
- network
47+
type: object
48+
status:
49+
properties:
4050
ips:
4151
description: The list of IP addresses (v4, v6) that were allocated
4252
for the pod interface
4353
items:
4454
type: string
4555
type: array
46-
network:
47-
description: The network attachment definition name for which this
48-
persistent allocation was created
49-
type: string
5056
required:
51-
- interface
5257
- ips
53-
- network
5458
type: object
5559
type: object
5660
served: true
5761
storage: true
62+
subresources:
63+
status: {}

cmd/example/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ func main() {
4040
Spec: v1alpha1.IPAMLeaseSpec{
4141
Network: "tenantblue",
4242
Interface: "iface321",
43-
IPs: []string{"winner", "winner", "chicken", "dinner"},
4443
},
4544
}
4645

47-
_, err = exampleClient.K8sV1alpha1().IPAMLeases("default").Create(
46+
ipamLease, err := exampleClient.K8sV1alpha1().IPAMLeases("default").Create(
4847
context.Background(),
4948
pip,
5049
metav1.CreateOptions{},
@@ -62,6 +61,16 @@ func main() {
6261
)
6362
}()
6463

64+
ipamLease.Status.IPs = []string{"winner", "winner", "chicken", "dinner"}
65+
_, err = exampleClient.K8sV1alpha1().IPAMLeases("default").UpdateStatus(
66+
context.Background(),
67+
ipamLease,
68+
metav1.UpdateOptions{},
69+
)
70+
if err != nil {
71+
glog.Fatalf("Error creating a dummy persistentIP object: %v", err)
72+
}
73+
6574
allPersistentIPs, err := exampleClient.K8sV1alpha1().IPAMLeases(metav1.NamespaceAll).List(
6675
context.Background(),
6776
metav1.ListOptions{},
@@ -73,5 +82,6 @@ func main() {
7382
for _, persistentIP := range allPersistentIPs.Items {
7483
fmt.Printf("IPAM lease name: %q\n", persistentIP.Name)
7584
fmt.Printf(" - spec: %v\n", persistentIP.Spec)
85+
fmt.Printf(" - status: %v\n", persistentIP.Status)
7686
}
7787
}

pkg/crd/persistentip/v1alpha1/apis/clientset/versioned/typed/persistentip/v1alpha1/fake/fake_ipamlease.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/crd/persistentip/v1alpha1/apis/clientset/versioned/typed/persistentip/v1alpha1/ipamlease.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/crd/persistentip/v1alpha1/types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,26 @@ import (
1616
// +kubebuilder:object:root=true
1717
// +kubebuilder:resource:path=ipamleases,singular=ipamlease,scope=Namespaced
1818
// +kubebuilder:storageversion
19+
// +kubebuilder:subresource:status
1920
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
2021

2122
// IPAMLease is the Schema for the IPAMLease API
2223
type IPAMLease struct {
2324
metav1.TypeMeta `json:",inline"`
2425
metav1.ObjectMeta `json:"metadata,omitempty"`
2526

26-
Spec IPAMLeaseSpec `json:"spec,omitempty"`
27+
Spec IPAMLeaseSpec `json:"spec,omitempty"`
28+
Status IPAMLeaseStatus `json:"status,omitempty"`
2729
}
2830

2931
type IPAMLeaseSpec struct {
3032
// The network attachment definition name for which this persistent allocation was created
3133
Network string `json:"network"`
3234
// The pod interface name for which this allocation was created
3335
Interface string `json:"interface"`
36+
}
37+
38+
type IPAMLeaseStatus struct {
3439
// The list of IP addresses (v4, v6) that were allocated for the pod interface
3540
IPs []string `json:"ips"`
3641
}

pkg/crd/persistentip/v1alpha1/zz_generated.deepcopy.go

Lines changed: 20 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)