Reputation: 251
I'm attemping to use the go api for gcloud to create a container.
I have a project set up:
$ gcloud projects list
PROJECT_ID NAME PROJECT_NUMBER
sql-manager-293118 sql-manager 789332021319
Also my application default credentials are configured.
The below code runs fine, but at the call to create the service I get the below error:
<p>The requested URL <code>/v1alpha1/projects/sql-manager-293118/services?alt=json&prettyPrint=false</code> was not found on this server. <ins>That’s all we know.</ins>
I've also run simpler requests using the api (for example listing all the available locations for this given service), and have been able to retrun data without issue.
Any guidance is appreciated.
package main
import (
"context"
"fmt"
// "sort"
"google.golang.org/api/option"
"google.golang.org/api/run/v1alpha1"
)
const (
createDefaultClientFlag = true
scopes = run.CloudPlatformScope
// List the Cloud Run services in this location
serviceName = "test"
locationsId = "us-central1"
projectId = "sql-manager-293118"
imageName = "gcr.io/cloudrun/hello"
)
func createDefaultClient(ctx context.Context) (*run.APIService, error) {
return run.NewService(ctx)
}
func main() {
// https://godoc.org/google.golang.org/api/run/v1#NewService
var err error = nil
var runService *run.APIService = nil
ctx := context.Background()
runService, err = createDefaultClient(ctx)
if err != nil {
fmt.Println("Error:", err)
return
}
projectsLocationsService := *run.NewProjectsLocationsService(runService)
// Define the service to deploy
tmpservice := &run.Service{
ApiVersion: "serving.knative.dev/v1alpha1",
Kind: "Service",
Metadata: &run.ObjectMeta{
Name: serviceName,
Namespace: projectId,
},
Spec: &run.ServiceSpec{
RunLatest: &run.ServiceSpecRunLatest{
Configuration: &run.ConfigurationSpec{
RevisionTemplate: &run.RevisionTemplate{
Metadata: &run.ObjectMeta{
DeletionGracePeriodSeconds: 0,
},
Spec: &run.RevisionSpec{
Container: &run.Container{
Image: imageName,
Resources: &run.ResourceRequirements{
Limits: map[string]string{"memory": "256Mi"},
},
Stdin: false,
StdinOnce: false,
Tty: false,
},
ContainerConcurrency: 80,
TimeoutSeconds: 300,
},
},
},
},
},
}
createCall := projectsLocationsService.Services.Create("projects/" + projectId, tmpservice)
service, err := createCall.Do()
fmt.Println(service, err)
if err != nil {
fmt.Printf("Error creating new locationservice: %s", err)
}
fmt.Printf("%#v", service.Spec)
}
Upvotes: 0
Views: 91
Reputation: 251
DazWilkin was correct, I should have been using /projects/${PROJECT}/locations/us-central1/
Upvotes: 1