Skip to content

Commit

Permalink
Adding GCPMachinePoolMachine to fufill MPM contract
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennenMM7 committed Apr 18, 2024
1 parent 49befae commit 14b660a
Show file tree
Hide file tree
Showing 25 changed files with 2,593 additions and 68 deletions.
3 changes: 3 additions & 0 deletions cloud/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ const (
// See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
// for annotation formatting rules.
CustomDataHashAnnotation = "sigs.k8s.io/cluster-api-provider-gcp-mig-custom-data-hash"

// ClusterAPIImagePrefix is the prefix for the image name used by the Cluster API provider for GCP.
ClusterAPIImagePrefix = "capi-ubuntu-1804-k8s-"
)
30 changes: 30 additions & 0 deletions cloud/gcperrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package gcperrors

import (
"net/http"
"strings"

"google.golang.org/api/googleapi"
)
Expand All @@ -43,3 +44,32 @@ func IgnoreNotFound(err error) error {

return err
}

// IsAlreadyDeleted reports whether err is a Google API error indicating that the resource is already being deleted.
func IsAlreadyDeleted(err error) bool {
if err == nil {
return false
}
ae, _ := err.(*googleapi.Error)

return strings.Contains(ae.Errors[0].Message, "Instance is already being deleted.")
}

// IsMemberNotFound reports whether err is a Google API error indicating that the member is not found.
func IsMemberNotFound(err error) bool {
if err == nil {
return false
}
ae, _ := err.(*googleapi.Error)

return strings.Contains(ae.Errors[0].Message, "is not a member of")
}

// PrintGCPError returns the error message from a Google API error.
func PrintGCPError(err error) string {
if err == nil {
return ""
}
ae, _ := err.(*googleapi.Error)
return ae.Message + " " + ae.Errors[0].Message + " " + ae.Errors[0].Reason
}
2 changes: 1 addition & 1 deletion cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (m *MachineScope) InstanceImageSpec() *compute.AttachedDisk {
if m.Machine.Spec.Version != nil {
version = *m.Machine.Spec.Version
}
image := "capi-ubuntu-1804-k8s-" + strings.ReplaceAll(semver.MajorMinor(version), ".", "-")
image := cloud.ClusterAPIImagePrefix + strings.ReplaceAll(semver.MajorMinor(version), ".", "-")
sourceImage := path.Join("projects", m.ClusterGetter.Project(), "global", "images", "family", image)
if m.GCPMachine.Spec.Image != nil {
sourceImage = *m.GCPMachine.Spec.Image
Expand Down
Loading

0 comments on commit 14b660a

Please sign in to comment.