Skip to content

Commit

Permalink
Merge pull request #1 from maiqueb/add-crd-clients-listers-informers
Browse files Browse the repository at this point in the history
code-gen: provide types and generator scripts
  • Loading branch information
maiqueb authored Aug 31, 2023
2 parents 4370e14 + 5b2946c commit d744077
Show file tree
Hide file tree
Showing 2,095 changed files with 994,401 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- name: Verify codegen
run: hack/verify-codegen.sh
env:
GOPATH: /home/runner/go

- name: Build the client example
run: go build -o _out/persistentips_dummy_client cmd/example/main.go
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/
_out/
57 changes: 57 additions & 0 deletions artifacts/k8s.cni.cncf.io_ipamleases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.13.0
name: ipamleases.k8s.cni.cncf.io
spec:
group: k8s.cni.cncf.io
names:
kind: IPAMLease
listKind: IPAMLeaseList
plural: ipamleases
singular: ipamlease
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: IPAMLease is the Schema for the IPAMLease API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
properties:
interface:
description: The pod interface name for which this allocation was
created
type: string
ips:
description: The list of IP addresses (v4, v6) that were allocated
for the pod interface
items:
type: string
type: array
network:
description: The network attachment definition name for which this
persistent allocation was created
type: string
required:
- interface
- ips
- network
type: object
type: object
served: true
storage: true
77 changes: 77 additions & 0 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"context"
"flag"
"fmt"

"github.com/golang/glog"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/clientcmd"

"github.com/maiqueb/persistentips/pkg/crd/persistentip/v1alpha1"
clientset "github.com/maiqueb/persistentips/pkg/crd/persistentip/v1alpha1/apis/clientset/versioned"
)

var (
kubeConfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
kubeAPIURL = flag.String("kube-api-url", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
)

func main() {
flag.Parse()

cfg, err := clientcmd.BuildConfigFromFlags(*kubeAPIURL, *kubeConfig)
if err != nil {
glog.Fatalf("Error building kubeconfig: %v", err)
}

exampleClient, err := clientset.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building example clientset: %v", err)
}

// create a persistent IP allocation
pip := &v1alpha1.IPAMLease{
ObjectMeta: metav1.ObjectMeta{
Name: "example",
},
Spec: v1alpha1.IPAMLeaseSpec{
Network: "tenantblue",
Interface: "iface321",
IPs: []string{"winner", "winner", "chicken", "dinner"},
},
}

_, err = exampleClient.K8sV1alpha1().IPAMLeases("default").Create(
context.Background(),
pip,
metav1.CreateOptions{},
)
if err != nil {
glog.Fatalf("Error creating a dummy persistentIP object: %v", err)
}

defer func() {
// teardown persistent IP
_ = exampleClient.K8sV1alpha1().IPAMLeases("default").Delete(
context.Background(),
pip.Name,
metav1.DeleteOptions{},
)
}()

allPersistentIPs, err := exampleClient.K8sV1alpha1().IPAMLeases(metav1.NamespaceAll).List(
context.Background(),
metav1.ListOptions{},
)
if err != nil {
glog.Fatalf("Error listing all persistentIP objects: %v", err)
}

for _, persistentIP := range allPersistentIPs.Items {
fmt.Printf("IPAM lease name: %q\n", persistentIP.Name)
fmt.Printf(" - spec: %v\n", persistentIP.Spec)
}
}
55 changes: 55 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module github.com/maiqueb/persistentips

go 1.20

require (
github.com/golang/glog v1.1.2
k8s.io/apimachinery v0.28.1
k8s.io/client-go v0.28.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/onsi/gomega v1.27.10 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230816210353-14e408962443 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit d744077

Please sign in to comment.