Skip to content

Commit

Permalink
Fix issues with Pgpool HealthChecker field and version check in webho…
Browse files Browse the repository at this point in the history
…ok (#1118)

Signed-off-by: MobarakHsn <mobarak@appscode.com>
  • Loading branch information
MobarakHsn authored Jan 19, 2024
1 parent e78c6ff commit b625c64
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions apis/kubedb/v1alpha2/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions apis/kubedb/v1alpha2/pgpool_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ func (p *Pgpool) SetDefaults() {
}
p.SetHealthCheckerDefaults()

ppVersion := &catalog.PgpoolVersion{}
ppVersion := catalog.PgpoolVersion{}
err := DefaultClient.Get(context.TODO(), types.NamespacedName{
Name: p.Spec.Version,
}, ppVersion)
}, &ppVersion)
if err != nil {
klog.Errorf("can't get the pgpool version object %s for %s \n", err.Error(), p.Spec.Version)
return
}
if p.Spec.PodTemplate != nil {
p.SetSecurityContext(ppVersion)
p.SetSecurityContext(&ppVersion)
}
}

Expand Down
2 changes: 1 addition & 1 deletion apis/kubedb/v1alpha2/pgpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type PgpoolSpec struct {
// HealthChecker defines attributes of the health checker
// +optional
// +kubebuilder:default={periodSeconds: 10, timeoutSeconds: 10, failureThreshold: 1}
HealthChecker *kmapi.HealthCheckSpec `json:"healthChecker"`
HealthChecker kmapi.HealthCheckSpec `json:"healthChecker"`

// TerminationPolicy controls the delete operation for Pgpool
// +optional
Expand Down
23 changes: 12 additions & 11 deletions apis/kubedb/v1alpha2/pgpool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ limitations under the License.
package v1alpha2

import (
"context"
"fmt"

catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"

"github.com/pkg/errors"
"gomodules.xyz/x/arrays"
core "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
kmapi "kmodules.xyz/client-go/api/v1"
ofst "kmodules.xyz/offshoot-api/api/v2"
Expand Down Expand Up @@ -152,7 +156,7 @@ func (p *Pgpool) ValidateCreateOrUpdate() field.ErrorList {
}
}

if err := p.ValidateHealth(p.Spec.HealthChecker); err != nil {
if err := p.ValidateHealth(&p.Spec.HealthChecker); err != nil {
errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("healthChecker"),
p.Name,
err.Error(),
Expand Down Expand Up @@ -191,17 +195,14 @@ func (p *Pgpool) ValidateHealth(health *kmapi.HealthCheckSpec) error {
}

func PgpoolValidateVersion(p *Pgpool) error {
version := p.Spec.Version
for _, v := range PgpoolAvailableVersions {
if v == version {
return nil
}
ppVersion := catalog.PgpoolVersion{}
err := DefaultClient.Get(context.TODO(), types.NamespacedName{
Name: p.Spec.Version,
}, &ppVersion)
if err != nil {
return errors.New("version not supported")
}
return errors.New("version not supported")
}

var PgpoolAvailableVersions = []string{
"4.4.2",
return nil
}

var PgpoolReservedVolumes = []string{
Expand Down
6 changes: 1 addition & 5 deletions apis/kubedb/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b625c64

Please sign in to comment.