Skip to content

Commit d744077

Browse files
authored
Merge pull request #1 from maiqueb/add-crd-clients-listers-informers
code-gen: provide types and generator scripts
2 parents 4370e14 + 5b2946c commit d744077

File tree

2,095 files changed

+994401
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,095 files changed

+994401
-0
lines changed

.github/workflows/test.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version-file: go.mod
20+
21+
- name: Verify codegen
22+
run: hack/verify-codegen.sh
23+
env:
24+
GOPATH: /home/runner/go
25+
26+
- name: Build the client example
27+
run: go build -o _out/persistentips_dummy_client cmd/example/main.go

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/
2+
_out/
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.13.0
7+
name: ipamleases.k8s.cni.cncf.io
8+
spec:
9+
group: k8s.cni.cncf.io
10+
names:
11+
kind: IPAMLease
12+
listKind: IPAMLeaseList
13+
plural: ipamleases
14+
singular: ipamlease
15+
scope: Namespaced
16+
versions:
17+
- name: v1alpha1
18+
schema:
19+
openAPIV3Schema:
20+
description: IPAMLease is the Schema for the IPAMLease API
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
spec:
35+
properties:
36+
interface:
37+
description: The pod interface name for which this allocation was
38+
created
39+
type: string
40+
ips:
41+
description: The list of IP addresses (v4, v6) that were allocated
42+
for the pod interface
43+
items:
44+
type: string
45+
type: array
46+
network:
47+
description: The network attachment definition name for which this
48+
persistent allocation was created
49+
type: string
50+
required:
51+
- interface
52+
- ips
53+
- network
54+
type: object
55+
type: object
56+
served: true
57+
storage: true

cmd/example/main.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"fmt"
7+
8+
"github.com/golang/glog"
9+
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/client-go/tools/clientcmd"
12+
13+
"github.com/maiqueb/persistentips/pkg/crd/persistentip/v1alpha1"
14+
clientset "github.com/maiqueb/persistentips/pkg/crd/persistentip/v1alpha1/apis/clientset/versioned"
15+
)
16+
17+
var (
18+
kubeConfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
19+
kubeAPIURL = flag.String("kube-api-url", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
20+
)
21+
22+
func main() {
23+
flag.Parse()
24+
25+
cfg, err := clientcmd.BuildConfigFromFlags(*kubeAPIURL, *kubeConfig)
26+
if err != nil {
27+
glog.Fatalf("Error building kubeconfig: %v", err)
28+
}
29+
30+
exampleClient, err := clientset.NewForConfig(cfg)
31+
if err != nil {
32+
glog.Fatalf("Error building example clientset: %v", err)
33+
}
34+
35+
// create a persistent IP allocation
36+
pip := &v1alpha1.IPAMLease{
37+
ObjectMeta: metav1.ObjectMeta{
38+
Name: "example",
39+
},
40+
Spec: v1alpha1.IPAMLeaseSpec{
41+
Network: "tenantblue",
42+
Interface: "iface321",
43+
IPs: []string{"winner", "winner", "chicken", "dinner"},
44+
},
45+
}
46+
47+
_, err = exampleClient.K8sV1alpha1().IPAMLeases("default").Create(
48+
context.Background(),
49+
pip,
50+
metav1.CreateOptions{},
51+
)
52+
if err != nil {
53+
glog.Fatalf("Error creating a dummy persistentIP object: %v", err)
54+
}
55+
56+
defer func() {
57+
// teardown persistent IP
58+
_ = exampleClient.K8sV1alpha1().IPAMLeases("default").Delete(
59+
context.Background(),
60+
pip.Name,
61+
metav1.DeleteOptions{},
62+
)
63+
}()
64+
65+
allPersistentIPs, err := exampleClient.K8sV1alpha1().IPAMLeases(metav1.NamespaceAll).List(
66+
context.Background(),
67+
metav1.ListOptions{},
68+
)
69+
if err != nil {
70+
glog.Fatalf("Error listing all persistentIP objects: %v", err)
71+
}
72+
73+
for _, persistentIP := range allPersistentIPs.Items {
74+
fmt.Printf("IPAM lease name: %q\n", persistentIP.Name)
75+
fmt.Printf(" - spec: %v\n", persistentIP.Spec)
76+
}
77+
}

go.mod

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
module github.com/maiqueb/persistentips
2+
3+
go 1.20
4+
5+
require (
6+
github.com/golang/glog v1.1.2
7+
k8s.io/apimachinery v0.28.1
8+
k8s.io/client-go v0.28.1
9+
)
10+
11+
require (
12+
github.com/davecgh/go-spew v1.1.1 // indirect
13+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
14+
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
15+
github.com/go-logr/logr v1.2.4 // indirect
16+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
17+
github.com/go-openapi/jsonreference v0.20.2 // indirect
18+
github.com/go-openapi/swag v0.22.3 // indirect
19+
github.com/gogo/protobuf v1.3.2 // indirect
20+
github.com/golang/protobuf v1.5.3 // indirect
21+
github.com/google/gnostic-models v0.6.8 // indirect
22+
github.com/google/go-cmp v0.5.9 // indirect
23+
github.com/google/gofuzz v1.2.0 // indirect
24+
github.com/google/uuid v1.3.0 // indirect
25+
github.com/imdario/mergo v0.3.6 // indirect
26+
github.com/josharian/intern v1.0.0 // indirect
27+
github.com/json-iterator/go v1.1.12 // indirect
28+
github.com/mailru/easyjson v0.7.7 // indirect
29+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
30+
github.com/modern-go/reflect2 v1.0.2 // indirect
31+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
32+
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
33+
github.com/onsi/gomega v1.27.10 // indirect
34+
github.com/pkg/errors v0.9.1 // indirect
35+
github.com/spf13/pflag v1.0.5 // indirect
36+
golang.org/x/net v0.14.0 // indirect
37+
golang.org/x/oauth2 v0.8.0 // indirect
38+
golang.org/x/sys v0.11.0 // indirect
39+
golang.org/x/term v0.11.0 // indirect
40+
golang.org/x/text v0.12.0 // indirect
41+
golang.org/x/time v0.3.0 // indirect
42+
golang.org/x/tools v0.12.0 // indirect
43+
google.golang.org/appengine v1.6.7 // indirect
44+
google.golang.org/protobuf v1.30.0 // indirect
45+
gopkg.in/inf.v0 v0.9.1 // indirect
46+
gopkg.in/yaml.v2 v2.4.0 // indirect
47+
gopkg.in/yaml.v3 v3.0.1 // indirect
48+
k8s.io/api v0.28.1 // indirect
49+
k8s.io/klog/v2 v2.100.1 // indirect
50+
k8s.io/kube-openapi v0.0.0-20230816210353-14e408962443 // indirect
51+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
52+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
53+
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
54+
sigs.k8s.io/yaml v1.3.0 // indirect
55+
)

0 commit comments

Comments
 (0)