github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/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 (
    29  	rTypes    common.CommaSeparatedStrings
    30  	boskosURL = flag.String("boskos-url", "http://boskos", "Boskos URL")
    31  )
    32  
    33  func init() {
    34  	flag.Var(&rTypes, "resource-type", "comma-separated list of resources need to be reset")
    35  }
    36  
    37  func main() {
    38  	logrus.SetFormatter(&logrus.JSONFormatter{})
    39  	boskos := client.NewClient("Reaper", *boskosURL)
    40  	logrus.Infof("Initialzied boskos client!")
    41  	flag.Parse()
    42  
    43  	if len(rTypes) == 0 {
    44  		logrus.Fatal("--resource-type must not be empty!")
    45  	}
    46  
    47  	for range time.Tick(time.Minute * 5) {
    48  		for _, r := range rTypes {
    49  			sync(boskos, r)
    50  		}
    51  	}
    52  }
    53  
    54  func sync(c *client.Client, res string) {
    55  	// kubetest busted
    56  	if owners, err := c.Reset(res, common.Busy, 30*time.Minute, common.Dirty); err != nil {
    57  		logrus.WithError(err).Error("Reset busy failed!")
    58  	} else {
    59  		logrus.Infof("Reset busy to dirty! Proj-owner: %v", owners)
    60  	}
    61  
    62  	// janitor, mason busted
    63  	if owners, err := c.Reset(res, common.Cleaning, 30*time.Minute, common.Dirty); err != nil {
    64  		logrus.WithError(err).Error("Reset cleaning failed!")
    65  	} else {
    66  		logrus.Infof("Reset cleaning to dirty! Proj-owner: %v", owners)
    67  	}
    68  
    69  	// mason busted
    70  	if owners, err := c.Reset(res, common.Leased, 30*time.Minute, common.Dirty); err != nil {
    71  		logrus.WithError(err).Error("Reset busy failed!")
    72  	} else {
    73  		logrus.Infof("Reset leased to dirty! Proj-owner: %v", owners)
    74  	}
    75  }