Skip to content

Commit

Permalink
Merge pull request #24 from att-cloudnative-labs/feature/name_change
Browse files Browse the repository at this point in the history
Change name to kubesweeper
  • Loading branch information
Tremaine Eto authored May 10, 2019
2 parents c1993f4 + e93253e commit b242d7c
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 59 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ COPY go.sum /app/go.sum

WORKDIR /app

RUN GIT_TERMINAL_PROMPT=1 GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build --installsuffix cgo --ldflags="-s" -o kubecrawler
RUN GIT_TERMINAL_PROMPT=1 GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build --installsuffix cgo --ldflags="-s" -o kubesweeper

# The second stage: Just what's needed
FROM alpine:3.8
# copy the binary and the settings into the container
COPY --from=builder /app/kubecrawler /app/kubecrawler
COPY --from=builder /app/kubesweeper /app/kubesweeper
COPY --from=builder /app/configs/ /app/configs/

WORKDIR /app

# Run it
ENTRYPOINT ["./kubecrawler"]
ENTRYPOINT ["./kubesweeper"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
docker build -t kubecrawler .
helm template kubecrawler --set image=kubecrawler | kubectl create -f -
docker build -t kubesweeper .
helm template kubesweeper --set image=kubesweeper | kubectl create -f -
go-build:
go build
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Kubesweeper

Automatically crawls through resources in a lab Kubernetes cluster and acts according to [certain conditions outlined here](#configuration-defaults). As of now, Kubernetes Deployment Crawler will delete deployments and their associated resources if the waiting reason and/or pod restart counts dictate.
Automatically iterates through resources in a lab Kubernetes cluster and acts according to [certain conditions outlined here](#configuration-defaults). As of now, Kubesweeper will delete deployments and their associated resources if the waiting reason and/or pod restart counts dictate.

If your lab Kubernetes clusters are filling up with non-Running pods, then the Kubernetes Deployment Crawler's automatic deletion
If your lab Kubernetes clusters are filling up with non-Running pods, then Kubesweeper's automatic deletion
can assist. Future iterations of this project can involve other actions based on crawling through Kubernetes cluster resources, such as generating reports per namespace without actually deleting.

Please note that Kubesweeper is intended for use in lab—not production, customer-facing—clusters.

<p align="center">
<img src="https://travis-ci.org/att-cloudnative-labs/kubesweeper.svg?branch=master">
<a href="https://goreportcard.com/report/github.com/att-cloudnative-labs/kubesweeper" alt="Go Report Card">
Expand Down Expand Up @@ -41,11 +43,11 @@ can assist. Future iterations of this project can involve other actions based on
</p>

## Deployment as a Kubernetes CronJob
If the desired cluster does not have Knative installed, then KubeCrawler can be installed as a Kubernetes CronJob.
If the desired cluster does not have Knative installed, then Kubesweeper can be installed as a Kubernetes CronJob.

1. Build docker image
```bash
$ docker build -t kubecrawler .
$ docker build -t kubesweeper .
```
2. Create Kubernetes resources from ```install``` directory
```bash
Expand All @@ -55,18 +57,18 @@ $ kubectl apply -f install/
Note that step 2 must be run in the context of the Kubernetes cluster. After that command is run, the appropriate Kubernetes resources will be created from the .yaml files in ```install```.

## Deployment as a Knative CronJobSource
If you wish to deploy the Kythera Kubernetes Deployment Crawler on Knative as a CronJobSource, you can use Helm. For information on installing Helm, please refer to the [Helm quickstart guide](https://helm.sh/docs/using_helm/). After installing Helm, the following steps can be manually run:
If you wish to deploy Kubesweeper on Knative as a CronJobSource, you can use Helm. For information on installing Helm, please refer to the [Helm quickstart guide](https://helm.sh/docs/using_helm/). After installing Helm, the following steps can be manually run:

1. Build docker image
```bash
$ docker build -t kubecrawler .
$ docker build -t kubesweeper .
```
2. Run helm template to install Kubecrawler
2. Run helm template to install Kubesweeper
```bash
$ helm template kubecrawler --set image=<KUBECRAWLER_IMAGE> | kubectl create -f -
$ helm template kubesweeper --set image=<KUBESWEEPER_IMAGE> | kubectl create -f -
```

In lieu of step 2, a Makefile can be used to pull values from ./helm/kubecrawler/values.yaml:
In lieu of step 2, a Makefile can be used to pull values from ./helm/kubesweeper/values.yaml:

```bash
$ make
Expand All @@ -84,33 +86,30 @@ Under the ```configs``` folder, the ```config.yaml``` has the following default
* Failed
* Pod restart threshold
* 144
* If the pod restart threshold is at least this number *and* has a pod waiting reason of ```CrashLoopBackOff```, then Kubernetes Deployment Crawler will delete the associated resources
* If the pod restart threshold is at least this number *and* has a pod waiting reason of ```CrashLoopBackOff```, then Kubesweeper will delete the associated resources

Function configurations can be found in ~/helm/kubecrawler/values.yaml
Helm function configurations can be found in ```~/helm/kubesweeper/values.yaml```.

*name: Name to use for deployment.
*image: Image used in deployment.
*cron: Cron expression used to schedule Crawler. Any valid cron expression can be used.
*namespace: Namespace job will be deployed in.
* name
* Name to use for deployment
* image
* Image used in deployment
* cron
* Cron expression used to schedule Kubesweeper
* Any valid cron expression can be used
* namespace
* Namespace job will be deployed in

## Contributing

1. [Fork Kubernetes Deployment Cleaner](https://github.com/att-cloudnative-labs/kubesweeper/fork)
1. [Fork Kubesweeper](https://github.com/att-cloudnative-labs/kubesweeper/fork)
2. Create your feature branch (`git checkout -b feature/fooBar`)
3. Commit your changes (`git commit -am 'Add some fooBar'`)
4. Push to the branch (`git push origin feature/fooBar`)
5. Create a new Pull Request

## Additional info

<p align="center">
<a href="https://kythera.io" alt="Kythera">
<img src="./images/kythera.png" height="40%" width="40%">
</a>
</p>

Part of Kythera: Kubernetes Projects for Developers and Operators – [kythera.io](https://kythera.io).

<p align="center">
<a href="https://github.com/att-cloudnative-labs" alt="AT&T Cloud Native Labs">
<img src="./images/cloud_native_labs.png" height="50%" width="50%">
Expand Down
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var ConfigObj = KleanerConfig{}

// This map would need to be updated to account for any other behavior we would want to enable
// The keys in this map have to map directly to the DeleteFuncString in the CrawlerConfigDetails struct
// The keys in this map have to map directly to the DeleteFuncString in the SweeperConfigDetails struct
var funcMap = map[string]DeleteFunc{
"DeleteCrash": DeleteCrash,
"DeleteGeneric": DeleteGeneric,
Expand All @@ -20,13 +20,13 @@ var funcMap = map[string]DeleteFunc{
* This is the parent config object
*/
type KleanerConfig struct {
Reasons []CrawlerConfigDetails `yaml:"reasons"`
Reasons []SweeperConfigDetails `yaml:"reasons"`
}

/**
* This is the object that holds the necessary information
*/
type CrawlerConfigDetails struct {
type SweeperConfigDetails struct {
Reason string `yaml:"reason"`
RestartThreshold int `yaml:"restartThreshold,omitempty"`
DeleteFuncString string `yaml:"deleteFuncString"`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/att-cloudnative-labs/kubernetes-deployment-crawler
module github.com/att-cloudnative-labs/kubesweeper

go 1.12

Expand Down
8 changes: 0 additions & 8 deletions helm/kubecrawler/values.yaml

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v1
appVersion: "0.0.1"
description: A Helm chart for Kubernetes
name: kubernetes-deployment-crawler
name: kubesweeper
version: 0.0.1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions helm/kubesweeper/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Default values for kubesweeper.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

name: kubesweeper
image: docker.io/att-cloudnative-labs/kubesweeper:v0.0.1-alpha
cron: 0 17 * * *
namespace: att-cloudnative-labs
Binary file removed images/kythera.png
Binary file not shown.
10 changes: 5 additions & 5 deletions install/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: kubernetes-deployment-crawler
namespace: kythera-system
name: kubesweeper
namespace: att-cloudnative-labs
spec:
concurrencyPolicy: Allow
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
serviceAccountName: kubernetes-deployment-crawler
serviceAccountName: kubesweeper
containers:
- args:
image: docker.io/attcloudnativelabs/kubernetes-deployment-crawler:v0.0.1-alpha
image: docker.io/att-cloudnative-labs/kubesweeper:v0.0.1-alpha
imagePullPolicy: Always
name: kubernetes-deployment-crawler
name: kubesweeper
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
Expand Down
2 changes: 1 addition & 1 deletion install/namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: kythera-system
name: att-cloudnative-labs
10 changes: 5 additions & 5 deletions install/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kubernetes-deployment-crawler
name: kubesweeper
rules:
- apiGroups:
- "apps"
Expand Down Expand Up @@ -33,12 +33,12 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubernetes-deployment-crawler
name: kubesweeper
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubernetes-deployment-crawler
name: kubesweeper
subjects:
- kind: ServiceAccount
name: kubernetes-deployment-crawler
namespace: kythera-system
name: kubesweeper
namespace: att-cloudnative-labs
4 changes: 2 additions & 2 deletions install/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: kubernetes-deployment-crawler
namespace: kythera-system
name: kubesweeper
namespace: att-cloudnative-labs
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
// initialize the config, from yaml or environment variables
var kleanerConfig = ConfigObj
// create the map that will hold the reasons and the config object
var waitingReasons = make(map[string]CrawlerConfigDetails)
var waitingReasons = make(map[string]SweeperConfigDetails)

// fill the map
for _, conf := range kleanerConfig.Reasons {
Expand All @@ -68,7 +68,7 @@ func main() {
panic(err.Error())
}

fmt.Println("Beginning the crawl.")
fmt.Println("Beginning the sweep.")

// get a list of pods for all namespaces
pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{})
Expand All @@ -83,7 +83,7 @@ func main() {
waiting := status.State.Waiting
if waiting != nil {
reason := waiting.Reason
if crawlerConfigDetails, ok := waitingReasons[reason]; ok {
if SweeperConfigDetails, ok := waitingReasons[reason]; ok {
fmt.Printf("Waiting reason match. %s/%s has a waiting reason of: %s\n", pod.Namespace,
pod.OwnerReferences[0].Name, reason)
rs, err := clientset.AppsV1().ReplicaSets(pod.Namespace).Get(pod.OwnerReferences[0].Name, metav1.GetOptions{})
Expand All @@ -98,7 +98,7 @@ func main() {
continue StatusLoop
}
if deploy != nil && deploy.Name != "" { // indicates something to be deleted
_, err = crawlerConfigDetails.DeleteFunction(clientset.AppsV1().Deployments(pod.Namespace), deploy, int(status.RestartCount), crawlerConfigDetails.RestartThreshold)
_, err = SweeperConfigDetails.DeleteFunction(clientset.AppsV1().Deployments(pod.Namespace), deploy, int(status.RestartCount), SweeperConfigDetails.RestartThreshold)
if err != nil {
fmt.Printf("Error deleting Deployment. Error: %s\n", err.Error())
continue StatusLoop
Expand Down

0 comments on commit b242d7c

Please sign in to comment.