Skip to content

Commit

Permalink
Merge pull request #1255 from redpanda-data/backend/redpanda_feature_…
Browse files Browse the repository at this point in the history
…check

backend: add check feature function and use that for security compati…
  • Loading branch information
bojand committed May 13, 2024
2 parents bb0426b + d2e45a5 commit 7cec6c9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
1 change: 0 additions & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/carlmjohnson/requests v0.23.5
github.com/cloudhut/common v0.10.0
github.com/cloudhut/connect-client v0.0.0-20240122153328-02a3103805d8
github.com/coreos/go-semver v0.3.1
github.com/docker/go-connections v0.5.0
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204
github.com/getkin/kin-openapi v0.124.0
Expand Down
2 changes: 0 additions & 2 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ github.com/containerd/containerd v1.7.16/go.mod h1:NL49g7A/Fui7ccmxV6zkBWwqMgmMx
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E=
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
Expand Down
32 changes: 17 additions & 15 deletions backend/pkg/console/endpoint_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"context"
"fmt"

"github.com/coreos/go-semver/semver"
"github.com/redpanda-data/common-go/rpadmin"
"github.com/twmb/franz-go/pkg/kmsg"
"github.com/twmb/franz-go/pkg/kversion"

Expand Down Expand Up @@ -49,11 +49,11 @@ func (s *Service) GetEndpointCompatibility(ctx context.Context) (EndpointCompati

// Required kafka requests per API endpoint
type endpoint struct {
URL string
Method string
Requests []kmsg.Request
HasRedpandaAPI bool
MinRedpandaVersion string
URL string
Method string
Requests []kmsg.Request
HasRedpandaAPI bool
RedpandaFeature string
}
endpointRequirements := []endpoint{
{
Expand Down Expand Up @@ -120,10 +120,10 @@ func (s *Service) GetEndpointCompatibility(ctx context.Context) (EndpointCompati
HasRedpandaAPI: true,
},
{
URL: consolev1alpha1connect.SecurityServiceName,
Method: "POST",
HasRedpandaAPI: true,
MinRedpandaVersion: "24.1.1-rc5", // no v prefix
URL: consolev1alpha1connect.SecurityServiceName,
Method: "POST",
HasRedpandaAPI: true,
RedpandaFeature: "role_based_access_control",
},
}

Expand Down Expand Up @@ -152,11 +152,13 @@ func (s *Service) GetEndpointCompatibility(ctx context.Context) (EndpointCompati
if endpointReq.HasRedpandaAPI && s.redpandaSvc != nil {
endpointSupported = true

if endpointReq.MinRedpandaVersion != "" {
minV, _ := semver.NewVersion(endpointReq.MinRedpandaVersion)
rpV, _ := semver.NewVersion(s.redpandaSvc.ClusterVersion())
if minV != nil && rpV != nil {
endpointSupported = rpV.Compare(*minV) >= 0
if endpointReq.RedpandaFeature != "" {
enabled, err := s.redpandaSvc.CheckFeature(ctx,
endpointReq.RedpandaFeature,
[]rpadmin.FeatureState{rpadmin.FeatureStateActive})
// only use result if no error
if err == nil {
endpointSupported = enabled
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions backend/pkg/redpanda/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,29 @@ func (s *Service) ClusterVersion() string {
trimmed = strings.ReplaceAll(trimmed, " ", "")
return strings.TrimLeft(trimmed, "v")
}

// CheckFeature checks whether redpanda has the specified feature in the specified state.
// Multiple states can be passed to check if feature state is any one of the given states.
// For example if "active" OR "available".
func (s *Service) CheckFeature(ctx context.Context, feature string, states []adminapi.FeatureState) (bool, error) {
fr, err := s.adminClient.GetFeatures(ctx)
if err != nil {
return false, err
}

match := false
for _, f := range fr.Features {
if f.Name == feature {
for _, s := range states {
if s == f.State {
match = true
break
}
}

break
}
}

return match, nil
}

0 comments on commit 7cec6c9

Please sign in to comment.