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
1 change: 1 addition & 0 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ proto:
# client for cli
protoc -I meta --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go_out=../cli/repository/meta/v1 --go-grpc_out=../cli/repository/meta/v1 meta/meta.proto
protoc -I feature --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go_out=../cli/repository/feature/v1 --go-grpc_out=../cli/repository/feature/v1 feature/feature.proto
protoc -I workload --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go_out=../cli/repository/workload/v1 --go-grpc_out=../cli/repository/workload/v1 workload/workload.proto
# client for UI
protoc -I meta --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go_out=../ui/repository/meta//v1 --go-grpc_out=../ui/repository/meta/v1 meta/meta.proto
protoc -I feature --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go_out=../ui/repository/feature/v1 --go-grpc_out=../ui/repository/feature/v1 feature/feature.proto
Expand Down
17 changes: 17 additions & 0 deletions api/workload/workload.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ message RestartResponse {
string message = 2;
}

// ServiceInfo contains information about the configured restart service
message ServiceInfo {
bool enabled = 1;
WorkloadType type = 2;
string name = 3;
}

// InfoRequest is an empty request for getting service info
message InfoRequest {
}

// SimpleRestartRequest is an empty request that uses configured values
message SimpleRestartRequest {
}

service Workload {
rpc RestartWorkload(RestartRequest) returns (RestartResponse);
rpc Info(InfoRequest) returns (ServiceInfo);
rpc Restart(SimpleRestartRequest) returns (RestartResponse);
}
3 changes: 3 additions & 0 deletions charts/feature/templates/service-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ data:
OPENTELEMETRY_ENDPOINT: {{ .Values.cli.opentelemetry.endpoint | quote }}
NOTIFICATION_ENABLED: {{ ternary "true" "false" .Values.service.notification.enabled | quote }}
NOTIFICATION_TYPE: {{ .Values.service.notification.type | quote }}
RESTART_ENABLED: {{ ternary "true" "false" .Values.service.restart.enabled | quote }}
RESTART_TYPE: {{ .Values.service.restart.type | quote }}
RESTART_NAME: {{ .Values.service.restart.name | quote }}
{{- end }}
4 changes: 4 additions & 0 deletions charts/feature/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ service:
notification:
enabled: false
type: ""
restart:
enabled: false
type: deployment
name: ""

cli:
# Deploy the feature CLI
Expand Down
16 changes: 16 additions & 0 deletions cli/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package command
import (
"github.com/dkrizic/feature/cli/constant"
feature "github.com/dkrizic/feature/cli/repository/feature/v1"
workload "github.com/dkrizic/feature/cli/repository/workload/v1"
"github.com/urfave/cli/v3"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
Expand All @@ -23,3 +24,18 @@ func FeatureClient(cmd *cli.Command) (feature.FeatureClient, error) {
fc := feature.NewFeatureClient(gc)
return fc, nil
}

func WorkloadClient(cmd *cli.Command) (workload.WorkloadClient, error) {
endpoint := cmd.String(constant.Endpoint)

gc, err := grpc.NewClient(endpoint,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
)
if err != nil {
return nil, err
}

wc := workload.NewWorkloadClient(gc)
return wc, nil
}
38 changes: 38 additions & 0 deletions cli/command/info/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package info

import (
"context"
"fmt"
"log/slog"

"github.com/dkrizic/feature/cli/command"
workload "github.com/dkrizic/feature/cli/repository/workload/v1"
"github.com/urfave/cli/v3"
"go.opentelemetry.io/otel"
)

func Info(ctx context.Context, cmd *cli.Command) error {
ctx, span := otel.Tracer("cli/command/info").Start(ctx, "Info")
defer span.End()

wc, err := command.WorkloadClient(cmd)
if err != nil {
return err
}

slog.InfoContext(ctx, "Getting service info")
result, err := wc.Info(ctx, &workload.InfoRequest{})
if err != nil {
return err
}

// Format output
output := fmt.Sprintf("Restart enabled: %t\n", result.Enabled)
if result.Enabled {
output += fmt.Sprintf("Restart type: %s\n", result.Type.String())
output += fmt.Sprintf("Restart name: %s\n", result.Name)
}

cmd.Writer.Write([]byte(output))
return nil
}
37 changes: 37 additions & 0 deletions cli/command/restart/restart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package restart

import (
"context"
"fmt"
"log/slog"

"github.com/dkrizic/feature/cli/command"
workload "github.com/dkrizic/feature/cli/repository/workload/v1"
"github.com/urfave/cli/v3"
"go.opentelemetry.io/otel"
)

func Restart(ctx context.Context, cmd *cli.Command) error {
ctx, span := otel.Tracer("cli/command/restart").Start(ctx, "Restart")
defer span.End()

wc, err := command.WorkloadClient(cmd)
if err != nil {
return err
}

slog.InfoContext(ctx, "Restarting configured service")
result, err := wc.Restart(ctx, &workload.SimpleRestartRequest{})
if err != nil {
return err
}

if result.Success {
cmd.Writer.Write([]byte(fmt.Sprintf("✓ %s\n", result.Message)))
} else {
cmd.Writer.Write([]byte(fmt.Sprintf("✗ %s\n", result.Message)))
return fmt.Errorf("restart failed: %s", result.Message)
}

return nil
}
12 changes: 12 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/dkrizic/feature/cli/command/delete"
"github.com/dkrizic/feature/cli/command/get"
"github.com/dkrizic/feature/cli/command/getall"
"github.com/dkrizic/feature/cli/command/info"
"github.com/dkrizic/feature/cli/command/preset"
"github.com/dkrizic/feature/cli/command/restart"
"github.com/dkrizic/feature/cli/command/set"
"github.com/dkrizic/feature/cli/constant"
"github.com/dkrizic/feature/cli/meta"
Expand Down Expand Up @@ -139,6 +141,16 @@ func main() {
},
},
},
&cli.Command{
Name: "info",
Usage: "Get service info including restart configuration",
Action: info.Info,
},
&cli.Command{
Name: "restart",
Usage: "Restart the configured service",
Action: restart.Restart,
},
},
}

Expand Down
4 changes: 2 additions & 2 deletions cli/repository/feature/v1/feature.pb.go

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

16 changes: 8 additions & 8 deletions cli/repository/feature/v1/feature_grpc.pb.go

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

4 changes: 2 additions & 2 deletions cli/repository/meta/v1/meta.pb.go

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

8 changes: 4 additions & 4 deletions cli/repository/meta/v1/meta_grpc.pb.go

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

Loading