Skip to content

Commit

Permalink
Change the name 'tty-exporter' to 'local-session-tracker'
Browse files Browse the repository at this point in the history
  • Loading branch information
zoetrope committed Sep 17, 2024
1 parent 8385e50 commit 3814f9b
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ jobs:
push: true
tags: ghcr.io/cybozu-go/login-protector:${{ inputs.tag }},ghcr.io/cybozu-go/login-protector:latest
target: login-protector
- name: Build and Push tty-exporter
- name: Build and Push local-session-tracker
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/cybozu-go/tty-exporter:${{ inputs.tag }},ghcr.io/cybozu-go/tty-exporter:latest
target: tty-exporter
tags: ghcr.io/cybozu-go/local-session-tracker:${{ inputs.tag }},ghcr.io/cybozu-go/local-session-tracker:latest
target: local-session-tracker
- name: Setup Git Config
run: |
git config --global user.name github-actions
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ COPY internal/ internal/

RUN CGO_ENABLED=0 go install -ldflags="-w -s" ./cmd/...

# Build the tty-exporter binary
FROM scratch AS tty-exporter
# Build the local-session-tracker binary
FROM scratch AS local-session-tracker
LABEL org.opencontainers.image.source="https://github.com/cybozu-go/login-protector"

COPY --from=build /go/bin/tty-exporter .
COPY --from=build /go/bin/local-session-tracker .
USER 10000:10000
ENTRYPOINT ["/tty-exporter"]
ENTRYPOINT ["/local-session-tracker"]

# Build the login-protector binary
FROM scratch AS login-protector
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Image URL to use all building/pushing image targets
PROTECTOR_IMG ?= login-protector:dev
EXPORTER_IMG ?= tty-exporter:dev
TRACKER_IMG ?= local-session-tracker:dev

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -83,17 +83,17 @@ run: manifests fmt vet ## Run a controller from your host.
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${PROTECTOR_IMG} . --target=login-protector
$(CONTAINER_TOOL) build -t ${EXPORTER_IMG} . --target=tty-exporter
$(CONTAINER_TOOL) build -t ${TRACKER_IMG} . --target=local-session-tracker

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
$(CONTAINER_TOOL) push ${PROTECTOR_IMG}
$(CONTAINER_TOOL) push ${EXPORTER_IMG}
$(CONTAINER_TOOL) push ${TRACKER_IMG}

.PHONY: load-image
load-image: docker-build setup
kind load docker-image ${PROTECTOR_IMG}
kind load docker-image ${EXPORTER_IMG}
kind load docker-image ${TRACKER_IMG}


.PHONY: build-installer
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ curl -fsL https://github.com/cybozu-go/login-protector/releases/latest/download/
login-protector targets only StatefulSets. The StatefulSet should be configured as follows:

1. Add the label `login-protector.cybozu.io/protect: "true"` to the StatefulSet.
2. Add the sidecar container `ghcr.io/cybozu-go/tty-exporter` and specify `shareProcessNamespace: true`.
2. Add the sidecar container `ghcr.io/cybozu-go/local-session-tracker` and specify `shareProcessNamespace: true`.
3. Set the `updateStrategy` to `type: OnDelete`.


Expand Down Expand Up @@ -71,8 +71,8 @@ spec:
image: ghcr.io/cybozu/ubuntu:22.04
imagePullPolicy: IfNotPresent
command: [ "sleep", "infinity" ]
- name: tty-exporter
image: ghcr.io/cybozu-go/tty-exporter:latest
- name: local-session-tracker
image: ghcr.io/cybozu-go/local-session-tracker:latest
imagePullPolicy: IfNotPresent
ports:
- name: sidecar
Expand All @@ -86,8 +86,8 @@ spec:
Annotations can be used to modify the behavior of login-protector for the target StatefulSet:
- `login-protector.cybozu.io/exporter-name`: Specify the name of the tty-exporter sidecar container. Default is "tty-exporter".
- `login-protector.cybozu.io/exporter-port`: Specify the port of the tty-exporter sidecar container. Default is "8080".
- `login-protector.cybozu.io/tracker-name`: Specify the name of the local-session-tracker sidecar container. Default is "local-session-tracker".
- `login-protector.cybozu.io/tracker-port`: Specify the port of the local-session-tracker sidecar container. Default is "8080".
- `login-protector.cybozu.io/no-pdb`: Set to "true" to prevent the creation of a PodDisruptionBudget.


Expand All @@ -99,8 +99,8 @@ metadata:
labels:
login-protector.cybozu.io/protect: "true"
annotations:
login-protector.cybozu.io/exporter-name: sidecar
login-protector.cybozu.io/exporter-port: "9090"
login-protector.cybozu.io/tracker-name: sidecar
login-protector.cybozu.io/tracker-port: "9090"
login-protector.cybozu.io/no-pdb: "true"
spec:
replicas: 1
Expand All @@ -119,7 +119,7 @@ spec:
imagePullPolicy: IfNotPresent
command: [ "sleep", "infinity" ]
- name: sidecar
image: ghcr.io/cybozu-go/tty-exporter:latest
image: ghcr.io/cybozu-go/local-session-tracker:latest
imagePullPolicy: IfNotPresent
ports:
- name: sidecar
Expand Down
16 changes: 8 additions & 8 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ COPY ./bin/login-protector /
CMD ["/login-protector"]
'''

EXPORTER_DOCKERFILE = '''FROM golang:alpine
TRACKER_DOCKERFILE = '''FROM golang:alpine
WORKDIR /
COPY ./bin/tty-exporter /
CMD ["/tty-exporter"]
COPY ./bin/local-session-tracker /
CMD ["/local-session-tracker"]
'''

# Generate manifests
Expand Down Expand Up @@ -39,11 +39,11 @@ docker_build_with_restart(
k8s_yaml("./test/testdata/statefulset.yaml")

docker_build_with_restart(
'tty-exporter:dev', '.',
dockerfile_contents=EXPORTER_DOCKERFILE,
entrypoint=['/tty-exporter', '--zap-devel=true'],
only=['./bin/tty-exporter'],
'local-session-tracker:dev', '.',
dockerfile_contents=TRACKER_DOCKERFILE,
entrypoint=['/local-session-tracker', '--zap-devel=true'],
only=['./bin/local-session-tracker'],
live_update=[
sync('./bin/tty-exporter', '/tty-exporter'),
sync('./bin/local-session-tracker', '/local-session-tracker'),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"syscall"

"github.com/cybozu-go/login-protector/internal/common"
tty_exporter "github.com/cybozu-go/login-protector/internal/tty-exporter"
local_session_tracker "github.com/cybozu-go/login-protector/internal/local-session-tracker"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
)
Expand All @@ -28,9 +28,9 @@ func newZapLogger() *zap.Logger {
func main() {
logger := newZapLogger()
defer logger.Sync() //nolint:errcheck
logger.Info("starting ttypdb-sidecar...")
logger.Info("starting local-session-tracker...")

tty_exporter.InitMetrics(logger)
local_session_tracker.InitMetrics(logger)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -52,7 +52,7 @@ func main() {
mux := http.NewServeMux()
mux.HandleFunc("/readyz", handleReadyz)
mux.Handle("/metrics", promhttp.Handler())
mux.Handle("/status", tty_exporter.NewStatusHandler(logger))
mux.Handle("/status", local_session_tracker.NewStatusHandler(logger))
server := http.Server{
Addr: fmt.Sprintf(":%d", httpServerPort),
Handler: common.NewProxyHTTPHandler(mux, logger),
Expand Down
4 changes: 2 additions & 2 deletions internal/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package common

const LabelKeyLoginProtectorProtect = "login-protector.cybozu.io/protect"
const AnnotationKeyNoPDB = "login-protector.cybozu.io/no-pdb"
const AnnotationKeyExporterName = "login-protector.cybozu.io/exporter-name"
const AnnotationKeyExporterPort = "login-protector.cybozu.io/exporter-port"
const AnnotationKeyTrackerName = "login-protector.cybozu.io/tracker-name"
const AnnotationKeyTrackerPort = "login-protector.cybozu.io/tracker-port"

const ValueTrue = "true"
const KindStatefulSet = "StatefulSet"
Expand Down
22 changes: 11 additions & 11 deletions internal/controller/pdb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
return ctrl.Result{}, err
}

exporterName := "tty-exporter"
if name, ok := sts.Annotations[common.AnnotationKeyExporterName]; ok {
exporterName = name
trackerName := "local-session-tracker"
if name, ok := sts.Annotations[common.AnnotationKeyTrackerName]; ok {
trackerName = name
}
exporterPort := "8080"
if port, ok := sts.Annotations[common.AnnotationKeyExporterPort]; ok {
exporterPort = port
trackerPort := "8080"
if port, ok := sts.Annotations[common.AnnotationKeyTrackerPort]; ok {
trackerPort = port
}
noPDB := false
if noPDBStr, ok := sts.Annotations[common.AnnotationKeyNoPDB]; ok {
Expand All @@ -68,7 +68,7 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R

errorList := make([]error, 0)
for _, pod := range podList.Items {
err = r.reconcilePDB(ctx, &pod, exporterName, exporterPort, noPDB)
err = r.reconcilePDB(ctx, &pod, trackerName, trackerPort, noPDB)
if err != nil {
errorList = append(errorList, err)
}
Expand All @@ -81,7 +81,7 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
return ctrl.Result{}, nil
}

func (r *PDBReconciler) reconcilePDB(ctx context.Context, pod *corev1.Pod, exporterName string, exporterPort string, noPDB bool) error {
func (r *PDBReconciler) reconcilePDB(ctx context.Context, pod *corev1.Pod, trackerName string, trackerPort string, noPDB bool) error {
logger := log.FromContext(ctx)

if pod.DeletionTimestamp != nil {
Expand Down Expand Up @@ -114,17 +114,17 @@ func (r *PDBReconciler) reconcilePDB(ctx context.Context, pod *corev1.Pod, expor
var container *corev1.Container
for _, c := range pod.Spec.Containers {
c := c
if c.Name == exporterName {
if c.Name == trackerName {
container = &c
break
}
}
if container == nil {
err := fmt.Errorf("failed to find sidecar container (Name: %s)", exporterName)
err := fmt.Errorf("failed to find sidecar container (Name: %s)", trackerName)
return err
}

resp, err := http.Get(fmt.Sprintf("http://%s:%s/status", podIP, exporterPort))
resp, err := http.Get(fmt.Sprintf("http://%s:%s/status", podIP, trackerPort))
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tty_exporter
package local_session_tracker

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tty_exporter
package local_session_tracker

import (
"math"
Expand All @@ -7,7 +7,7 @@ import (
"go.uber.org/zap"
)

const metricsNamespace = "tty_exporter"
const metricsNamespace = "local_session_tracker"

func InitMetrics(logger *zap.Logger) {
prometheus.MustRegister(prometheus.NewGaugeFunc(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tty_exporter
package local_session_tracker

import (
"encoding/json"
Expand Down
8 changes: 4 additions & 4 deletions test/testdata/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ spec:
image: ghcr.io/cybozu/ubuntu:22.04
imagePullPolicy: IfNotPresent
command: [ "sleep", "infinity" ]
- name: tty-exporter
image: ghcr.io/cybozu-go/tty-exporter:0.0.1
- name: local-session-tracker
image: local-session-tracker:dev
imagePullPolicy: IfNotPresent
ports:
- name: sidecar
Expand Down Expand Up @@ -51,8 +51,8 @@ spec:
image: ghcr.io/cybozu/ubuntu:22.04
imagePullPolicy: IfNotPresent
command: [ "sleep", "infinity" ]
- name: tty-exporter
image: ghcr.io/cybozu-go/tty-exporter:0.0.1
- name: local-session-tracker
image: local-session-tracker:dev
imagePullPolicy: IfNotPresent
ports:
- name: sidecar
Expand Down

0 comments on commit 3814f9b

Please sign in to comment.