func initCloudSQL()

in analytics/server.go [167:215]


func initCloudSQL() (*app, error) {
	var err error
	a := &app{}

	if os.Getenv("DB_HOST") != "" {
		a.db, err = initTCPConnectionPool()
		if err != nil {
			log.Fatalf("initTCPConnectionPool: unable to connect: %s", err)
		}
	} else {
		a.db, err = initSocketConnectionPool()
		if err != nil {
			log.Fatalf("initSocketConnectionPool: unable to connect: %s", err)
		}
	}

	tableCreate := `
	CREATE TABLE IF NOT EXISTS CLUSTERS3(
		ClusterId 						TEXT, 
		CreateId 						TEXT, 
		Version							TEXT,
		GitCommit						TEXT,
		Timestamp 						TIMESTAMP,
		OS								TEXT,
		TerraformState 					TEXT,
		Region 							TEXT,
		EnableWorkloadIdentity 			BOOL, 
		EnablePreemptibleNodepool 		BOOL, 
		DefaultNodepoolOS 				TEXT,
		PrivateEndpoint 				BOOL,
		EnableConfigSync        		BOOL, 
		EnablePolicyController 			BOOL,
		AnthosServiceMesh				BOOL,
		MultiClusterGateway				BOOL,
		VPCType 						TEXT,
		ClusterIndex 					INTEGER,
		ClusterNumNodes 				INTEGER, 
		ClusterMachineType 				TEXT,
		ClusterRegion 					TEXT,
		ClusterZone 					TEXT 
	 );`

	// Create the Cluster table if it does not already exist.
	if _, err = a.db.Exec(tableCreate); err != nil {
		return a, fmt.Errorf("Error on table create: %s", err.Error())
	}

	return a, nil
}