github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/boskos/reaper/reaper.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"flag"
    21  	"time"
    22  
    23  	"github.com/sirupsen/logrus"
    24  	"k8s.io/test-infra/boskos/client"
    25  	"k8s.io/test-infra/boskos/common"
    26  )
    27  
    28  var rTypes common.ResTypes
    29  
    30  func init() {
    31  	flag.Var(&rTypes, "resource-type", "comma-separated list of resources need to be cleaned up")
    32  }
    33  
    34  func main() {
    35  	logrus.SetFormatter(&logrus.JSONFormatter{})
    36  	boskos := client.NewClient("Reaper", "http://boskos")
    37  	logrus.Infof("Initialzied boskos client!")
    38  	flag.Parse()
    39  
    40  	if len(rTypes) == 0 {
    41  		logrus.Fatal("--resource-type must not be empty!")
    42  	}
    43  
    44  	for range time.Tick(time.Minute * 5) {
    45  		for _, r := range rTypes {
    46  			sync(boskos, r)
    47  		}
    48  	}
    49  }
    50  
    51  func sync(c *client.Client, res string) {
    52  	// kubetest busted
    53  	if owners, err := c.Reset(res, "busy", 30*time.Minute, "dirty"); err != nil {
    54  		logrus.WithError(err).Error("Reset busy failed!")
    55  	} else {
    56  		logrus.Infof("Reset busy to dirty! Proj-owner: %v", owners)
    57  	}
    58  
    59  	// janitor busted
    60  	if owners, err := c.Reset(res, "cleaning", 30*time.Minute, "dirty"); err != nil {
    61  		logrus.WithError(err).Error("Reset cleaning failed!")
    62  	} else {
    63  		logrus.Infof("Reset cleaning to dirty! Proj-owner: %v", owners)
    64  	}
    65  }