Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/cloudproduct/cloudproduct.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"agones.dev/agones/pkg/cloudproduct/generic"
"agones.dev/agones/pkg/cloudproduct/gke"
"agones.dev/agones/pkg/portallocator"
"agones.dev/agones/pkg/util/errors"
"agones.dev/agones/pkg/util/runtime"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"github.com/spf13/viper"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -67,6 +67,7 @@ const (
)

var (
errs = errors.FromPackage()
logger = runtime.NewLoggerWithSource("cloudproduct")
productDetectors = []func(context.Context, *kubernetes.Clientset) string{gke.Detect}
)
Expand All @@ -92,7 +93,7 @@ func NewFromFlag(ctx context.Context, kc *kubernetes.Clientset) (ControllerHooks
case GenericProduct:
return generic.New(), nil
}
return nil, errors.Errorf("unknown cloud product: %q", product)
return nil, errs.Errorf("unknown cloud product: %q", product)
}

func autoDetect(ctx context.Context, product string, kc *kubernetes.Clientset) string {
Expand Down
10 changes: 6 additions & 4 deletions pkg/cloudproduct/eviction/eviction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ package eviction

import (
agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
"github.com/pkg/errors"
"agones.dev/agones/pkg/util/errors"
corev1 "k8s.io/api/core/v1"
)

var errs = errors.FromPackage()

// SetEviction sets disruptions controls on a Pod based on GameServer.Status.Eviction.
func SetEviction(eviction *agonesv1.Eviction, pod *corev1.Pod) error {
if eviction == nil {
return errors.New("No eviction value set. Should be the default value")
return errs.New("No eviction value set. Should be the default value")
}
if _, exists := pod.ObjectMeta.Annotations[agonesv1.PodSafeToEvictAnnotation]; !exists {
switch eviction.Safe {
Expand All @@ -35,7 +37,7 @@ func SetEviction(eviction *agonesv1.Eviction, pod *corev1.Pod) error {
// (on Autopilot, this enables Extended Duration pods, which is equivalent).
pod.ObjectMeta.Annotations[agonesv1.PodSafeToEvictAnnotation] = agonesv1.False
default:
return errors.Errorf("unknown eviction.safe value %q", string(eviction.Safe))
return errs.Errorf("unknown eviction.safe value %q", string(eviction.Safe))
}
}
if _, exists := pod.ObjectMeta.Labels[agonesv1.SafeToEvictLabel]; !exists {
Expand All @@ -50,7 +52,7 @@ func SetEviction(eviction *agonesv1.Eviction, pod *corev1.Pod) error {
// For EvictionSafeNever, match gones-gameserver-safe-to-evict-false PDB.
pod.ObjectMeta.Labels[agonesv1.SafeToEvictLabel] = agonesv1.False
default:
return errors.Errorf("unknown eviction.safe value %q", string(eviction.Safe))
return errs.Errorf("unknown eviction.safe value %q", string(eviction.Safe))
}
}
return nil
Expand Down
9 changes: 5 additions & 4 deletions pkg/cloudproduct/gke/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"agones.dev/agones/pkg/client/informers/externalversions"
"agones.dev/agones/pkg/cloudproduct/eviction"
"agones.dev/agones/pkg/portallocator"
"agones.dev/agones/pkg/util/errors"
"agones.dev/agones/pkg/util/runtime"
"cloud.google.com/go/compute/metadata"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand All @@ -51,6 +51,7 @@ var (
}
noWorkloadDefaulter = fmt.Sprintf("found no MutatingWebhookConfigurations matching %v", autopilotMutatingWebhooks)

errs = errors.FromPackage()
logger = runtime.NewLoggerWithSource("gke")
)

Expand Down Expand Up @@ -113,7 +114,7 @@ func (*gkeAutopilot) SyncPodPortsToGameServer(gs *agonesv1.GameServer, pod *core
}
var hpa hostPortAssignment
if err := json.Unmarshal([]byte(annotation), &hpa); err != nil {
return errors.Wrapf(err, "could not unmarshal annotation %s (value %q)", hostPortAssignmentAnnotation, annotation)
return errs.Wrapf(err, "could not unmarshal annotation %s (value %q)", hostPortAssignmentAnnotation, annotation)
}
for i, p := range gs.Spec.Ports {
if newPort, ok := hpa.PortsAssigned[p.HostPort]; ok {
Expand Down Expand Up @@ -218,7 +219,7 @@ func setEvictionNoExtended(ev *agonesv1.Eviction, pod *corev1.Pod) error {
delete(pod.ObjectMeta.Annotations, agonesv1.PodSafeToEvictAnnotation)
}
if ev == nil {
return errors.New("No eviction value set. Should be the default value")
return errs.New("No eviction value set. Should be the default value")
}
if _, exists := pod.ObjectMeta.Labels[agonesv1.SafeToEvictLabel]; !exists {
switch ev.Safe {
Expand All @@ -231,7 +232,7 @@ func setEvictionNoExtended(ev *agonesv1.Eviction, pod *corev1.Pod) error {
case agonesv1.EvictionSafeNever:
pod.ObjectMeta.Labels[agonesv1.SafeToEvictLabel] = agonesv1.False
default:
return errors.Errorf("eviction.safe == %s, which webhook should have rejected on Autopilot", ev.Safe)
return errs.Errorf("eviction.safe == %s, which webhook should have rejected on Autopilot", ev.Safe)
}
}
return nil
Expand Down