Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding GCPMachinePool Functionality #901

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions cloud/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2023 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cloud
BrennenMM7 marked this conversation as resolved.
Show resolved Hide resolved

const (
// CustomDataHashAnnotation is the key for the machine object annotation
// which tracks the hash of the custom data.
// 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-2204-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
}
10 changes: 10 additions & 0 deletions cloud/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ type Machine interface {
MachineGetter
MachineSetter
}

// MachinePoolGetter is an interface which can get machine pool information.
type MachinePoolGetter interface {
Project() string
}

// MachinePool is an interface which can get machine pool information.
type MachinePool interface {
MachinePoolGetter
}
2 changes: 1 addition & 1 deletion cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,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