Skip to content

Commit 26d74c7

Browse files
authored
Add missing code doc for delete functions and write readme sections (#10)
* Add first part of readme This part explains the reason behind why we implemented the repo and how to get the code. * Change the delete function signature * Add code doc for delete functions
1 parent 21c76d8 commit 26d74c7

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

README.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
# go-kube
2-
go-kube is a wrapper over the kubectl commands such that we can have a nice interface that we can call from our go code
2+
go-kube is a wrapper over the kubectl commands such that we can have a nice interface that we can call from our go code.
3+
4+
**Why is this repo created?**
5+
6+
We (@andreaswachs and @Arneproductions) experienced many times while developing tools for Kubernetes that we were missing the ability to just call an apply or delete function that had the same behavior as Kubectl. We found ourselves, trying to implement the exact same logic as kubectl apply over and over again. This is of course a hassle, since we need to figure out how to create a specific resource or how to patch existing resources and choosing the correct patch method.
7+
8+
So we asked ourself... why reinvent the wheel? Kubectl has some nice commands that does this for us. But the code around kubectl can be really cumbersome and hard to understand. So for that reason we have implemented this little tool that simplifies the interface for all us developers.
9+
10+
## Get started
11+
In order to get started you need to get the package to your project.
12+
```
13+
go get github.com/Arneproductions/go-kube
14+
```
15+
16+
Now in order to use the functions you need to import the following package in your go file:
17+
```go
18+
import github.com/Arneproductions/go-kube/pkg/kubectl
19+
```
20+
21+
This lets you call the functions like the following:
22+
```go
23+
opts := kubectl.ApplyManifestsOptions{
24+
Recursive: false
25+
}
26+
27+
kubectl.ApplyManifests(ctx, pathToKubeconfig, opts, pathToManifests...)
28+
```

pkg/kubectl/delete.go

+43-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,52 @@ type deleteOptions struct {
2222
IsKustomization bool `default:"false"`
2323
}
2424

25-
func DeleteManifests(ctx context.Context, kubeconfigPath string, opts *deleteOptions, filePaths ...string) error {
25+
/*
26+
DeleteManifests deletes the resource created by the given manifest files from the cluster that the kubeconfigPath points to.
27+
28+
Example:
29+
30+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
31+
defer cancel()
32+
33+
err := DeleteManifests(
34+
ctx,
35+
"/path/to/kubeconfig",
36+
[]string{"path/to/file1", "path/to/file2"}...
37+
)
38+
39+
if err != nil {
40+
// Handle error
41+
}
42+
*/
43+
func DeleteManifests(ctx context.Context, kubeconfigPath string, filePaths ...string) error {
44+
45+
opts := &deleteOptions{}
46+
2647
return deleteFunc(ctx, kubeconfigPath, opts, filePaths...)
2748
}
2849

29-
func DeleteKustomization(ctx context.Context, kubeconfigPath string, opts *deleteOptions, filePaths ...string) error {
50+
/*
51+
DeleteKustomization deletes the resources created by the given kustomization files from the cluster that the kubeconfigPath points to.
52+
53+
Example:
54+
55+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
56+
defer cancel()
57+
58+
err := DeleteKustomization(
59+
ctx,
60+
"/path/to/kubeconfig",
61+
[]string{"path/to/kustomization1", "path/to/kustomization2"}...
62+
)
63+
64+
if err != nil {
65+
// Handle error
66+
}
67+
*/
68+
func DeleteKustomization(ctx context.Context, kubeconfigPath string, filePaths ...string) error {
69+
70+
opts := &deleteOptions{}
3071
opts.IsKustomization = true // Force IsKustomization to true
3172

3273
return deleteFunc(ctx, kubeconfigPath, opts, filePaths...)

0 commit comments

Comments
 (0)