Skip to content

Commit

Permalink
cmd: provision then cleanup a persistent allocation
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Aug 31, 2023
1 parent 3e06a01 commit 7f98396
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
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"
)

Expand All @@ -31,6 +32,36 @@ func main() {
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.CniV1alpha1().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.CniV1alpha1().IPAMLeases("default").Delete(
context.Background(),
pip.Name,
metav1.DeleteOptions{},
)
}()

allPersistentIPs, err := exampleClient.CniV1alpha1().IPAMLeases(metav1.NamespaceAll).List(
context.Background(),
metav1.ListOptions{},
Expand Down

0 comments on commit 7f98396

Please sign in to comment.