...

Source file src/k8s.io/kubernetes/test/integration/util/cloud.go

Documentation: k8s.io/kubernetes/test/integration/util

     1  //go:build !providerless
     2  // +build !providerless
     3  
     4  /*
     5  Copyright 2018 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package util
    21  
    22  import (
    23  	"time"
    24  
    25  	"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
    26  	"golang.org/x/oauth2"
    27  	"k8s.io/legacy-cloud-providers/gce"
    28  )
    29  
    30  const (
    31  	// TestProjectID is the project id used for creating NewMockGCECloud
    32  	TestProjectID = "test-project"
    33  	// TestNetworkProjectID is the network project id for creating NewMockGCECloud
    34  	TestNetworkProjectID = "net-test-project"
    35  	// TestRegion is the region for creating NewMockGCECloud
    36  	TestRegion = "test-region"
    37  	// TestZone is the zone for creating NewMockGCECloud
    38  	TestZone = "test-zone"
    39  	// TestNetworkName is the network name for creating NewMockGCECloud
    40  	TestNetworkName = "test-network"
    41  	// TestSubnetworkName is the sub network name for creating NewMockGCECloud
    42  	TestSubnetworkName = "test-sub-network"
    43  	// TestSecondaryRangeName is the secondary range name for creating NewMockGCECloud
    44  	TestSecondaryRangeName = "test-secondary-range"
    45  )
    46  
    47  type mockTokenSource struct{}
    48  
    49  func (*mockTokenSource) Token() (*oauth2.Token, error) {
    50  	return &oauth2.Token{
    51  		AccessToken:  "access",
    52  		TokenType:    "Bearer",
    53  		RefreshToken: "refresh",
    54  		Expiry:       time.Now().Add(1 * time.Hour),
    55  	}, nil
    56  }
    57  
    58  // NewMockGCECloud returns a handle to a Cloud instance that is
    59  // served by a mock http server
    60  func NewMockGCECloud(cloud cloud.Cloud) (*gce.Cloud, error) {
    61  	config := &gce.CloudConfig{
    62  		ProjectID:          TestProjectID,
    63  		NetworkProjectID:   TestNetworkProjectID,
    64  		Region:             TestRegion,
    65  		Zone:               TestZone,
    66  		ManagedZones:       []string{TestZone},
    67  		NetworkName:        TestNetworkName,
    68  		SubnetworkName:     TestSubnetworkName,
    69  		SecondaryRangeName: TestSecondaryRangeName,
    70  		NodeTags:           []string{},
    71  		UseMetadataServer:  false,
    72  		TokenSource:        &mockTokenSource{},
    73  	}
    74  	return gce.CreateGCECloudWithCloud(config, cloud)
    75  }
    76  

View as plain text