in custom-targets/vertex-ai/model-deployer/vertexai.go [150:191]
func undeployNoTrafficModels(ctx context.Context, aiPlatformService *aiplatform.Service, endpointName string) error {
endpoint, err := aiPlatformService.Projects.Locations.Endpoints.Get(endpointName).Do()
if err != nil {
return fmt.Errorf("unable to fetch endpoint where model was deployed: %v", err)
}
var modelsToUndeploy = map[string]bool{}
for _, dm := range endpoint.DeployedModels {
modelsToUndeploy[dm.Id] = true
}
for id, split := range endpoint.TrafficSplit {
// model does not get un-deployed if its configured to receive traffic
if split != 0 {
delete(modelsToUndeploy, id)
}
}
undeployedCount := 0
err = nil
var lros []*aiplatform.GoogleLongrunningOperation
for id, _ := range modelsToUndeploy {
undeployRequest := &aiplatform.GoogleCloudAiplatformV1UndeployModelRequest{DeployedModelId: id}
lro, lroErr := aiPlatformService.Projects.Locations.Endpoints.UndeployModel(endpointName, undeployRequest).Do()
if err != nil {
fmt.Printf("error undeploying model: %v\n", err)
err = lroErr
undeployedCount += 1
} else {
lros = append(lros, lro)
}
}
for pollErr := range pollChan(ctx, aiPlatformService, lros...) {
if pollErr != nil {
fmt.Printf("Error in undeploy model operation: %v", err)
err = pollErr
}
}
return err
}