in apis/v1alpha1/collector_webhook.go [72:144]
func (c CollectorWebhook) defaulter(r *AmazonCloudWatchAgent) error {
if len(r.Spec.Mode) == 0 {
r.Spec.Mode = ModeDeployment
}
if len(r.Spec.UpgradeStrategy) == 0 {
r.Spec.UpgradeStrategy = UpgradeStrategyAutomatic
}
if r.Labels == nil {
r.Labels = map[string]string{}
}
if r.Labels["app.kubernetes.io/managed-by"] == "" {
r.Labels["app.kubernetes.io/managed-by"] = "amazon-cloudwatch-agent-operator"
}
// We can default to one because dependent objects Deployment and HorizontalPodAutoScaler
// default to 1 as well.
one := int32(1)
if r.Spec.Replicas == nil {
r.Spec.Replicas = &one
}
if r.Spec.TargetAllocator.Enabled && r.Spec.TargetAllocator.Replicas == nil {
r.Spec.TargetAllocator.Replicas = &one
}
if r.Spec.MaxReplicas != nil || (r.Spec.Autoscaler != nil && r.Spec.Autoscaler.MaxReplicas != nil) {
if r.Spec.Autoscaler == nil {
r.Spec.Autoscaler = &AutoscalerSpec{}
}
if r.Spec.Autoscaler.MaxReplicas == nil {
r.Spec.Autoscaler.MaxReplicas = r.Spec.MaxReplicas
}
if r.Spec.Autoscaler.MinReplicas == nil {
if r.Spec.MinReplicas != nil {
r.Spec.Autoscaler.MinReplicas = r.Spec.MinReplicas
} else {
r.Spec.Autoscaler.MinReplicas = r.Spec.Replicas
}
}
if r.Spec.Autoscaler.TargetMemoryUtilization == nil && r.Spec.Autoscaler.TargetCPUUtilization == nil {
defaultCPUTarget := int32(90)
r.Spec.Autoscaler.TargetCPUUtilization = &defaultCPUTarget
}
}
// if pdb isn't provided, we set MaxUnavailable 1,
// which will work even if there is just one replica,
// not blocking node drains but preventing out-of-the-box
// from disruption generated by them with replicas > 1
if r.Spec.PodDisruptionBudget == nil {
r.Spec.PodDisruptionBudget = &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
}
}
if r.Spec.Ingress.Type == IngressTypeRoute && r.Spec.Ingress.Route.Termination == "" {
r.Spec.Ingress.Route.Termination = TLSRouteTerminationTypeEdge
}
if r.Spec.Ingress.Type == IngressTypeNginx && r.Spec.Ingress.RuleType == "" {
r.Spec.Ingress.RuleType = IngressRuleTypePath
}
// If someone upgrades to a later version without upgrading their CRD they will not have a management state set.
// This results in a default state of unmanaged preventing reconciliation from continuing.
if len(r.Spec.ManagementState) == 0 {
r.Spec.ManagementState = ManagementStateManaged
}
return nil
}