Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: Remove BuildGitInfo #1109

Merged
merged 2 commits into from
Oct 14, 2024
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
4 changes: 1 addition & 3 deletions autoscale-scheduler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ ARG GIT_INFO
COPY . .
# NOTE: Build flags here must be the same as in the base image, otherwise we'll rebuild
# dependencies. See /Dockerfile.go-base for detail on the "why".
RUN CGO_ENABLED=0 go build \
-ldflags "-X 'github.com/neondatabase/autoscaling/pkg/util.BuildGitInfo=$GIT_INFO'" \
autoscale-scheduler/cmd/*.go
RUN CGO_ENABLED=0 go build autoscale-scheduler/cmd/*.go

FROM alpine:3.19
COPY --from=builder /workspace/main /usr/bin/kube-scheduler
Expand Down
1 change: 0 additions & 1 deletion autoscale-scheduler/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func main() {
logConfig := zap.NewProductionConfig()
logConfig.Sampling = nil // Disable sampling, which the production config enables by default.
logger := zap.Must(logConfig.Build()).Named("autoscale-scheduler")
logger.Info("", zap.Any("buildInfo", util.GetBuildInfo()))

if err := runProgram(logger); err != nil {
log.Fatal(err)
Expand Down
4 changes: 1 addition & 3 deletions autoscaler-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ ARG GIT_INFO
COPY . .
# NOTE: Build env vars here must be the same as in the base image, otherwise we'll rebuild
# dependencies.
RUN CGO_ENABLED=0 go build \
-ldflags "-X 'github.com/neondatabase/autoscaling/pkg/util.BuildGitInfo=$GIT_INFO'" \
autoscaler-agent/cmd/*.go
RUN CGO_ENABLED=0 go build autoscaler-agent/cmd/*.go

FROM alpine:3.19
COPY --from=builder /workspace/main /usr/bin/autoscaler-agent
Expand Down
2 changes: 0 additions & 2 deletions autoscaler-agent/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func main() {
logger := zap.Must(logConfig.Build()).Named("autoscaler-agent")
defer logger.Sync() //nolint:errcheck // what are we gonna do, log something about it?

logger.Info("", zap.Any("buildInfo", util.GetBuildInfo()))

envArgs, err := agent.ArgsFromEnv()
if err != nil {
logger.Panic("Failed to get args from environment", zap.Error(err))
Expand Down
10 changes: 4 additions & 6 deletions pkg/agent/dumpstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
)

type StateDump struct {
Stopped bool `json:"stopped"`
BuildInfo util.BuildInfo `json:"buildInfo"`
Pods []podStateDump `json:"pods"`
Stopped bool `json:"stopped"`
Pods []podStateDump `json:"pods"`
}

func (s *agentState) StartDumpStateServer(shutdownCtx context.Context, logger *zap.Logger, config *DumpStateConfig) error {
Expand Down Expand Up @@ -85,9 +84,8 @@ func (s *agentState) DumpState(ctx context.Context, stopped bool) (*StateDump, e
}

state := StateDump{
Stopped: stopped,
BuildInfo: util.GetBuildInfo(),
Pods: make([]podStateDump, len(podList)),
Stopped: stopped,
Pods: make([]podStateDump, len(podList)),
}

wg := sync.WaitGroup{}
Expand Down
10 changes: 4 additions & 6 deletions pkg/plugin/dumpstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ func (c *dumpStateConfig) validate() (string, error) {
}

type stateDump struct {
Stopped bool `json:"stopped"`
BuildInfo util.BuildInfo `json:"buildInfo"`
State pluginStateDump `json:"state"`
Stopped bool `json:"stopped"`
State pluginStateDump `json:"state"`
}

func (p *AutoscaleEnforcer) startDumpStateServer(shutdownCtx context.Context, logger *zap.Logger) error {
Expand Down Expand Up @@ -87,9 +86,8 @@ func (p *AutoscaleEnforcer) dumpState(ctx context.Context, stopped bool) (*state
}

return &stateDump{
Stopped: stopped,
BuildInfo: util.GetBuildInfo(),
State: *state,
Stopped: stopped,
State: *state,
}, nil
}

Expand Down
13 changes: 1 addition & 12 deletions pkg/plugin/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,25 +1234,14 @@ func (e *AutoscaleEnforcer) startMigration(ctx context.Context, logger *zap.Logg
return false, fmt.Errorf("Error checking if migration exists: %w", err)
}

gitVersion := util.GetBuildInfo().GitInfo
// FIXME: make this not depend on GetBuildInfo() internals.
if gitVersion == "<unknown>" {
gitVersion = "unknown"
}

vmm := &vmapi.VirtualMachineMigration{
ObjectMeta: metav1.ObjectMeta{
// TODO: it's maybe possible for this to run into name length limits? Unclear what we
// should do if that happens.
Name: vmmName.Name,
Namespace: pod.name.Namespace,
Labels: map[string]string{
// NB: There's requirements on what constitutes a valid label. Thankfully, the
// output of `git describe` always will.
//
// See also:
// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
LabelPluginCreatedMigration: gitVersion,
LabelPluginCreatedMigration: "true",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it okay that the format of the label value has changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup -- double-checked that the only place we use this label is here:

metav1.ListOptions{
// NB: Including just the label itself means that we select for objects that *have* the
// label, without caring about the actual value.
//
// See also:
// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#set-based-requirement
LabelSelector: LabelPluginCreatedMigration,
},

... where we don't require that it's set to any particular value :)

},
},
Spec: vmapi.VirtualMachineMigrationSpec{
Expand Down
47 changes: 0 additions & 47 deletions pkg/util/buildinfo.go

This file was deleted.

Loading