Skip to content

Commit

Permalink
linter pass
Browse files Browse the repository at this point in the history
  • Loading branch information
kralicky committed Sep 11, 2023
1 parent ff8dffe commit 95c1df4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
50 changes: 25 additions & 25 deletions pkg/plugins/driverutil/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,37 @@ type BaseConfigServer[
}

// GetConfiguration implements ConfigurableServerInterface.
func (d *BaseConfigServer[R, HR, T]) GetConfiguration(ctx context.Context, in *GetRequest) (T, error) {
return d.tracker.GetConfigOrDefault(ctx, in.GetRevision())
func (s *BaseConfigServer[R, HR, T]) GetConfiguration(ctx context.Context, in *GetRequest) (T, error) {
return s.tracker.GetConfigOrDefault(ctx, in.GetRevision())
}

// GetDefaultConfiguration implements ConfigurableServerInterface.
func (d *BaseConfigServer[R, HR, T]) GetDefaultConfiguration(ctx context.Context, in *GetRequest) (T, error) {
return d.tracker.GetDefaultConfig(ctx, in.GetRevision())
func (s *BaseConfigServer[R, HR, T]) GetDefaultConfiguration(ctx context.Context, in *GetRequest) (T, error) {
return s.tracker.GetDefaultConfig(ctx, in.GetRevision())
}

// Install implements ConfigurableServerInterface.
func (d *BaseConfigServer[R, HR, T]) Install(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
func (s *BaseConfigServer[R, HR, T]) Install(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
var t T
t = t.ProtoReflect().New().Interface().(T)
d.setEnabled(t, lo.ToPtr(true))
err := d.tracker.ApplyConfig(ctx, t)
s.setEnabled(t, lo.ToPtr(true))
err := s.tracker.ApplyConfig(ctx, t)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to install monitoring cluster: %s", err.Error())
}
return &emptypb.Empty{}, nil
}

// ResetDefaultConfiguration implements ConfigurableServerInterface.
func (d *BaseConfigServer[R, HR, T]) ResetDefaultConfiguration(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
if err := d.tracker.ResetDefaultConfig(ctx); err != nil {
func (s *BaseConfigServer[R, HR, T]) ResetDefaultConfiguration(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
if err := s.tracker.ResetDefaultConfig(ctx); err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}

// ResetConfiguration implements ConfigurableServerInterface.
func (d *BaseConfigServer[R, HR, T]) ResetConfiguration(ctx context.Context, in R) (*emptypb.Empty, error) {
func (s *BaseConfigServer[R, HR, T]) ResetConfiguration(ctx context.Context, in R) (*emptypb.Empty, error) {
// If T contains a field named "enabled", assume it has installation semantics
// and ensure a non-nil mask is always passed to ResetConfig. This ensures
// the active config is never deleted from the underlying store, and therefore
Expand All @@ -107,43 +107,43 @@ func (d *BaseConfigServer[R, HR, T]) ResetConfiguration(ctx context.Context, in
patch.ProtoReflect().Clear(enabledField)
}
}
if err := d.tracker.ResetConfig(ctx, in.GetMask(), in.GetPatch()); err != nil {
if err := s.tracker.ResetConfig(ctx, in.GetMask(), in.GetPatch()); err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}

// SetConfiguration implements ConfigurableServerInterface.
func (d *BaseConfigServer[R, HR, T]) SetConfiguration(ctx context.Context, t T) (*emptypb.Empty, error) {
d.setEnabled(t, nil)
if err := d.tracker.ApplyConfig(ctx, t); err != nil {
func (s *BaseConfigServer[R, HR, T]) SetConfiguration(ctx context.Context, t T) (*emptypb.Empty, error) {
s.setEnabled(t, nil)
if err := s.tracker.ApplyConfig(ctx, t); err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}

// SetDefaultConfiguration implements ConfigurableServerInterface.
func (d *BaseConfigServer[R, HR, T]) SetDefaultConfiguration(ctx context.Context, t T) (*emptypb.Empty, error) {
d.setEnabled(t, nil)
if err := d.tracker.SetDefaultConfig(ctx, t); err != nil {
func (s *BaseConfigServer[R, HR, T]) SetDefaultConfiguration(ctx context.Context, t T) (*emptypb.Empty, error) {
s.setEnabled(t, nil)
if err := s.tracker.SetDefaultConfig(ctx, t); err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}

// Uninstall implements ConfigurableServerInterface.
func (d *BaseConfigServer[R, HR, T]) Uninstall(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
func (s *BaseConfigServer[R, HR, T]) Uninstall(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
var t T
t = t.ProtoReflect().New().Interface().(T)
d.setEnabled(t, lo.ToPtr(false))
err := d.tracker.ApplyConfig(ctx, t)
s.setEnabled(t, lo.ToPtr(false))
err := s.tracker.ApplyConfig(ctx, t)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to uninstall monitoring cluster: %s", err.Error())
}
return &emptypb.Empty{}, nil
}

func (d *BaseConfigServer[R, HR, T]) setEnabled(t T, enabled *bool) {
func (s *BaseConfigServer[R, HR, T]) setEnabled(t T, enabled *bool) {
field := util.FieldByName[T]("enabled")
if field == nil {
return
Expand All @@ -156,14 +156,14 @@ func (d *BaseConfigServer[R, HR, T]) setEnabled(t T, enabled *bool) {
}
}

func (k *BaseConfigServer[R, HR, T]) ConfigurationHistory(ctx context.Context, req *ConfigurationHistoryRequest) (HR, error) {
func (s *BaseConfigServer[R, HR, T]) ConfigurationHistory(ctx context.Context, req *ConfigurationHistoryRequest) (HR, error) {
options := []storage.HistoryOpt{
storage.IncludeValues(req.GetIncludeValues()),
}
if req.Revision != nil {
options = append(options, storage.WithRevision(req.GetRevision().GetRevision()))
}
revisions, err := k.tracker.History(ctx, req.GetTarget(), options...)
revisions, err := s.tracker.History(ctx, req.GetTarget(), options...)
resp := util.NewMessage[HR]()
if err != nil {
return resp, err
Expand All @@ -183,6 +183,6 @@ func (k *BaseConfigServer[R, HR, T]) ConfigurationHistory(ctx context.Context, r
return resp, nil
}

func (k *BaseConfigServer[R, HR, T]) Tracker() *DefaultingConfigTracker[T] {
return k.tracker
func (s *BaseConfigServer[R, HR, T]) Tracker() *DefaultingConfigTracker[T] {
return s.tracker
}
10 changes: 5 additions & 5 deletions pkg/plugins/driverutil/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/samber/lo"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/fieldmaskpb"

"github.com/rancher/opni/pkg/plugins/driverutil"
_ "github.com/rancher/opni/pkg/test/setup"
"github.com/rancher/opni/pkg/test/testdata/plugins/ext"
"github.com/rancher/opni/pkg/test/testutil"
"github.com/rancher/opni/pkg/util"
"github.com/rancher/opni/pkg/util/merge"
"github.com/rancher/opni/pkg/util/protorand"
"github.com/samber/lo"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/fieldmaskpb"
)

var _ = Describe("Base Config Server", Ordered, func() {
var _ = Describe("Base Config Server", Label("unit"), Ordered, func() {
var server *driverutil.BaseConfigServer[
*ext.SampleResetRequest,
*ext.SampleConfigurationHistoryResponse,
Expand Down
1 change: 1 addition & 0 deletions pkg/test/conformance/driverutil/config_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ func DefaultingConfigTrackerTestSuite[
historyDefault, err := configTracker.History(ctx, driverutil.Target_DefaultConfiguration, storage.IncludeValues(true))
Expect(err).NotTo(HaveOccurred())
historyActive, err := configTracker.History(ctx, driverutil.Target_ActiveConfiguration, storage.IncludeValues(true))
Expect(err).NotTo(HaveOccurred())
Expect(historyDefault).To(HaveLen(2))
Expect(historyDefault[0].Value()).NotTo(testutil.ProtoEqual(cfg1))
Expect(historyDefault[1].Value()).NotTo(testutil.ProtoEqual(cfg2))
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/fieldmask/masks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"google.golang.org/protobuf/types/known/fieldmaskpb"
)

var _ = Describe("Masks", func() {
var _ = Describe("Masks", Label("unit"), func() {
DescribeTable("using a field mask to keep only the specified fields",
func(msg *ext.SampleMessage, mask *fieldmaskpb.FieldMask, expected *ext.SampleMessage) {
fieldmask.ExclusiveKeep(msg, mask)
Expand Down
2 changes: 1 addition & 1 deletion web/pkg/opni/api/opni.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as CortexOpsService from '@pkg/opni/generated/github.com/rancher/opni/plugins/metrics/apis/cortexops/cortexops_svc';
import * as CortexOpsTypes from '@pkg/opni/generated/github.com/rancher/opni/plugins/metrics/apis/cortexops/cortexops_pb';
import * as StorageTypes from '@pkg/opni/generated/github.com/rancher/opni/internal/cortex/config/storage/storage_pb';
import * as DryRunTypes from '@pkg/opni/generated/github.com/rancher/opni/pkg/plugins/driverutil/dryrun_pb';
import * as DryRunTypes from '@pkg/opni/generated/github.com/rancher/opni/pkg/plugins/driverutil/types_pb';

export const CortexOps = {
service: CortexOpsService,
Expand Down

0 comments on commit 95c1df4

Please sign in to comment.