mirror of https://github.com/knative/pkg.git
use boskos to fetch a project if only a project is not specified (#1169)
This commit is contained in:
parent
aa5b1f2211
commit
777b215a64
|
@ -78,6 +78,8 @@ type GKECluster struct {
|
|||
Request *GKERequest
|
||||
// Project might be GKE specific, so put it here
|
||||
Project string
|
||||
// IsBoskos is true if the GCP project used is managed by boskos
|
||||
IsBoskos bool
|
||||
// NeedsCleanup tells whether the cluster needs to be deleted afterwards
|
||||
// This probably should be part of task wrapper's logic
|
||||
NeedsCleanup bool
|
||||
|
@ -181,12 +183,13 @@ func (gc *GKECluster) Acquire() error {
|
|||
|
||||
// Get project name from boskos if running in Prow, otherwise it should fail
|
||||
// since we don't know which project to use
|
||||
if common.IsProw() {
|
||||
if gc.Request.Project == "" && common.IsProw() {
|
||||
project, err := gc.boskosOps.AcquireGKEProject(gc.Request.ResourceType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed acquiring boskos project: '%v'", err)
|
||||
}
|
||||
gc.Project = project.Name
|
||||
gc.IsBoskos = true
|
||||
}
|
||||
if gc.Project == "" {
|
||||
return errors.New("GCP project must be set")
|
||||
|
@ -268,7 +271,7 @@ func (gc *GKECluster) Delete() error {
|
|||
gc.ensureProtected()
|
||||
// Release Boskos if running in Prow, will let Janitor taking care of
|
||||
// clusters deleting
|
||||
if common.IsProw() {
|
||||
if gc.IsBoskos {
|
||||
log.Printf("Releasing Boskos resource: '%v'", gc.Project)
|
||||
return gc.boskosOps.ReleaseGKEProject(gc.Project)
|
||||
}
|
||||
|
|
|
@ -1042,6 +1042,7 @@ func TestAcquire(t *testing.T) {
|
|||
func TestDelete(t *testing.T) {
|
||||
type testdata struct {
|
||||
isProw bool
|
||||
isBoskos bool
|
||||
NeedsCleanup bool
|
||||
requestCleanup bool
|
||||
boskosState []*boskoscommon.Resource
|
||||
|
@ -1146,6 +1147,7 @@ func TestDelete(t *testing.T) {
|
|||
name: "In prow, only need to release boskos",
|
||||
td: testdata{
|
||||
isProw: true,
|
||||
isBoskos: true,
|
||||
NeedsCleanup: true,
|
||||
requestCleanup: false,
|
||||
boskosState: []*boskoscommon.Resource{{
|
||||
|
@ -1226,6 +1228,7 @@ func TestDelete(t *testing.T) {
|
|||
}
|
||||
fgc := setupFakeGKECluster()
|
||||
fgc.Project = fakeProj
|
||||
fgc.IsBoskos = data.isBoskos
|
||||
fgc.NeedsCleanup = data.NeedsCleanup
|
||||
fgc.Request = &GKERequest{
|
||||
Request: gke.Request{
|
||||
|
@ -1260,9 +1263,9 @@ func TestDelete(t *testing.T) {
|
|||
gotCluster, _ = fgc.operations.GetCluster(fakeProj, data.cluster.Location, "", data.cluster.Name)
|
||||
}
|
||||
gotBoskos := fgc.boskosOps.(*boskosFake.FakeBoskosClient).GetResources()
|
||||
errMsg := fmt.Sprintf("testing deleting cluster, with:\n\tIs Prow: '%v'\n\tNeed cleanup: '%v'\n\t"+
|
||||
errMsg := fmt.Sprintf("testing deleting cluster, with:\n\tIs Prow: '%v'\n\tIs Boskos: '%v'\n\tNeed cleanup: '%v'\n\t"+
|
||||
"Request cleanup: '%v'\n\texisting cluster: '%v'\n\tboskos state: '%v'",
|
||||
data.isProw, data.NeedsCleanup, data.requestCleanup, data.cluster, data.boskosState)
|
||||
data.isProw, data.isBoskos, data.NeedsCleanup, data.requestCleanup, data.cluster, data.boskosState)
|
||||
if !reflect.DeepEqual(err, tt.want.Err) {
|
||||
t.Errorf("%s\nerror got: '%v'\nerror want: '%v'", errMsg, err, tt.want.Err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue