Skip to content

Commit

Permalink
added IPs and endpoints for whereami and inference apps
Browse files Browse the repository at this point in the history
  • Loading branch information
knee-berts committed Oct 16, 2024
1 parent fe72bfc commit b2a73d0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 217 deletions.
108 changes: 40 additions & 68 deletions cli/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,37 +103,9 @@ func InitConf(cfgFile string) *Config {
}
// Enable GCP APIs - Temporarily adding all apis needed to deal with flakes in the enable service TF module
serviceIds := []string{
// "iam.googleapis.com",
// "storage.googleapis.com",
"compute.googleapis.com",
// "logging.googleapis.com",
// "monitoring.googleapis.com",
// "containerregistry.googleapis.com",
// "container.googleapis.com",
// "binaryauthorization.googleapis.com",
// "stackdriver.googleapis.com",
// "iap.googleapis.com",
// "cloudresourcemanager.googleapis.com",
// "dns.googleapis.com",
// "iamcredentials.googleapis.com",
// "stackdriver.googleapis.com",
// "cloudkms.googleapis.com",
}
enableService(conf.ClustersProjectID, serviceIds)
// anthosServiceIds := []string{
// "anthos.googleapis.com",
// "gkehub.googleapis.com",
// "sourcerepo.googleapis.com",
// "anthosconfigmanagement.googleapis.com",
// "anthos.googleapis.com",
// "gkehub.googleapis.com",
// "multiclusterservicediscovery.googleapis.com",
// "multiclusteringress.googleapis.com",
// "trafficdirector.googleapis.com",
// "mesh.googleapis.com",
// "multiclustermetering.googleapis.com",
// }
// enableService(conf.ClustersProjectID, anthosServiceIds)

// Validate config
err = ValidateConf(conf)
Expand Down Expand Up @@ -230,11 +202,11 @@ func ValidateConf(c *Config) error {
if c.VpcConfig.VpcName == "" {
return fmt.Errorf("VPC Name cannot be empty")
}
// err := validateVPC(c.VpcConfig.VpcName, c.VpcConfig.VpcProjectID)
// if err != nil {
// return err
// }
// log.Printf("🌐 VPC name %s is valid + does not yet exist in VPC project %s\n", c.VpcConfig.VpcName, c.VpcConfig.VpcProjectID)
err := validateVPC(c.VpcConfig.VpcName, c.VpcConfig.VpcProjectID)
if err != nil {
return err
}
log.Printf("🌐 VPC name %s is valid + does not yet exist in VPC project %s\n", c.VpcConfig.VpcName, c.VpcConfig.VpcProjectID)

// Validate each ClusterConfig
for i, cc := range c.ClustersConfig {
Expand Down Expand Up @@ -285,43 +257,43 @@ func validateNodeOS(nodeOS string) error {
// NOTE - the ListRegionsRequest client lib function is returning an empty list for any GCP
// project. ListZones works fine. So for now, using ListZones result (where each zone has a region)
// to bootstrap a list of valid regions.
// func validateConfigRegion(projectID, region string) error {
// ctx := context.Background()
// c, err := compute.NewZonesRESTClient(ctx)
// if err != nil {
// return err
// }
// defer c.Close()
func validateConfigRegion(projectID, region string) error {
ctx := context.Background()
c, err := compute.NewZonesRESTClient(ctx)
if err != nil {
return err
}
defer c.Close()

// req := &computepb.ListZonesRequest{
// Project: projectID,
// }
// it := c.List(ctx, req)
// // Use zones to populate a map of valid regions for this project
// regions := map[string]bool{}
// for {
// resp, err := it.Next()
// if err == iterator.Done {
// break
// }
// if err != nil {
// return err
// }
// r := resp.GetRegion()
// spl := strings.Split(r, "/")
// if len(spl) < 2 {
// return fmt.Errorf("error validating region (%s) - GCP region (%s) is invalid\n", region, r)
// }
// sanitizedRegion := spl[len(spl)-1]
// regions[sanitizedRegion] = true
// }
req := &computepb.ListZonesRequest{
Project: projectID,
}
it := c.List(ctx, req)
// Use zones to populate a map of valid regions for this project
regions := map[string]bool{}
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
return err
}
r := resp.GetRegion()
spl := strings.Split(r, "/")
if len(spl) < 2 {
return fmt.Errorf("error validating region (%s) - GCP region (%s) is invalid\n", region, r)
}
sanitizedRegion := spl[len(spl)-1]
regions[sanitizedRegion] = true
}

// // check if Config.Region is in the map.
// if _, ok := regions[region]; !ok {
// return fmt.Errorf("config-wide region %s not found. Must be one of: %v\n", region, regions)
// }
// return nil
// }
// check if Config.Region is in the map.
if _, ok := regions[region]; !ok {
return fmt.Errorf("config-wide region %s not found. Must be one of: %v\n", region, regions)
}
return nil
}

// Validate region + zone for specific clusters.
func validateRegionAndZone(projectId string, clusterRegion string, clusterZones []string) error {
Expand Down
7 changes: 7 additions & 0 deletions terraform/modules/clusters/clusters.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
* limitations under the License.
*/

locals {
// Presets for project and network settings
project_id = var.shared_vpc ? var.vpc_project_id : var.project_id
network = "projects/${local.project_id}/global/networks/${var.vpc_name}"
vpc_selflink = format("projects/%s/global/networks/%s", local.project_id, var.vpc_name)
}

# Create clusters listing in the cluster_config variable
resource "google_container_cluster" "gke_ap" {
for_each = var.cluster_config
Expand Down
118 changes: 0 additions & 118 deletions terraform/modules/clusters/main.tf

This file was deleted.

3 changes: 0 additions & 3 deletions terraform/modules/clusters/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ terraform {
}
}

data "google_client_openid_userinfo" "me" {
}

provider "google" {
project = var.project_id
region = var.region
Expand Down
2 changes: 1 addition & 1 deletion terraform/modules/fleet/admin-cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
resource "google_container_cluster" "admin" {
provider = google-beta
name = "gke-ap-admin-cp-00"
project = var.project_id
project = var.fleet_project
location = "us-central1"
enable_autopilot = true
initial_node_count = 1
Expand Down
27 changes: 0 additions & 27 deletions terraform/modules/fleet/data.tf

This file was deleted.

4 changes: 4 additions & 0 deletions terraform/modules/fleet/mcg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

data "google_project" "fleet_project" {
project_id = var.fleet_project
}

// Hydrate
locals{
whereami_openapi_spec = <<-EOT
Expand Down

0 comments on commit b2a73d0

Please sign in to comment.