-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add version and manifests for service monitor
- Loading branch information
Showing
12 changed files
with
215 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ COPY raspi-fan-control /bin/raspi-fan-control | |
USER nobody | ||
|
||
ENTRYPOINT [ "/bin/raspi-fan-control" ] | ||
|
||
EXPOSE 9001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.PHONY: clean lint build | ||
|
||
# Set version variables for LDFLAGS | ||
GIT_VERSION ?= $(shell git describe --tags --always --dirty) | ||
GIT_HASH ?= $(shell git rev-parse HEAD) | ||
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ' | ||
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) | ||
ifdef SOURCE_DATE_EPOCH | ||
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)") | ||
else | ||
BUILD_DATE ?= $(shell date "$(DATE_FMT)") | ||
endif | ||
GIT_TREESTATE = "clean" | ||
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi) | ||
ifeq ($(DIFF), 1) | ||
GIT_TREESTATE = "dirty" | ||
endif | ||
|
||
PKG=github.com/cpanato/raspi-fan-control/cmd | ||
LDFLAGS="-X $(PKG).GitVersion=$(GIT_VERSION) -X $(PKG).gitCommit=$(GIT_HASH) -X $(PKG).gitTreeState=$(GIT_TREESTATE) -X $(PKG).buildDate=$(BUILD_DATE)" | ||
|
||
.PHONY: release | ||
release: | ||
LDFLAGS=$(LDFLAGS) goreleaser release --rm-dist | ||
|
||
.PHONY: snapshot-pr | ||
snapshot-pr: | ||
LDFLAGS=$(LDFLAGS) goreleaser release --rm-dist --snapshot --skip-publish --skip-sign | ||
|
||
.PHONY: snapshot | ||
snapshot: | ||
LDFLAGS=$(LDFLAGS) goreleaser release --rm-dist --snapshot --skip-publish --skip-sign |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
"text/tabwriter" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Base version information. | ||
// | ||
// This is the fallback data used when version information from git is not | ||
// provided via go ldflags (e.g. via Makefile). | ||
var ( | ||
// Output of "git describe". The prerequisite is that the branch should be | ||
// tagged using the correct versioning strategy. | ||
GitVersion string = "devel" | ||
// SHA1 from git, output of $(git rev-parse HEAD) | ||
gitCommit = "unknown" | ||
// State of git tree, either "clean" or "dirty" | ||
gitTreeState = "unknown" | ||
// Build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
buildDate = "unknown" | ||
) | ||
|
||
type versionOptions struct { | ||
json bool | ||
} | ||
|
||
var versionOpts = &versionOptions{} | ||
|
||
// verifyCmd represents the verify command | ||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "fan-control version", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runVersion(versionOpts) | ||
}, | ||
} | ||
|
||
func init() { | ||
versionCmd.PersistentFlags().BoolVarP(&versionOpts.json, "json", "j", false, | ||
"print JSON instead of text") | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
|
||
func runVersion(opts *versionOptions) error { | ||
v := VersionInfo() | ||
res := v.String() | ||
|
||
if opts.json { | ||
j, err := v.JSONString() | ||
if err != nil { | ||
return errors.Wrap(err, "unable to generate JSON from version info") | ||
} | ||
res = j | ||
} | ||
|
||
fmt.Println(res) | ||
return nil | ||
} | ||
|
||
type Info struct { | ||
GitVersion string | ||
GitCommit string | ||
GitTreeState string | ||
BuildDate string | ||
GoVersion string | ||
Compiler string | ||
Platform string | ||
} | ||
|
||
func VersionInfo() Info { | ||
// These variables typically come from -ldflags settings and in | ||
// their absence fallback to the global defaults set above. | ||
return Info{ | ||
GitVersion: GitVersion, | ||
GitCommit: gitCommit, | ||
GitTreeState: gitTreeState, | ||
BuildDate: buildDate, | ||
GoVersion: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||
} | ||
} | ||
|
||
// String returns the string representation of the version info | ||
func (i *Info) String() string { | ||
b := strings.Builder{} | ||
w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0) | ||
|
||
fmt.Fprintf(w, "GitVersion:\t%s\n", i.GitVersion) | ||
fmt.Fprintf(w, "GitCommit:\t%s\n", i.GitCommit) | ||
fmt.Fprintf(w, "GitTreeState:\t%s\n", i.GitTreeState) | ||
fmt.Fprintf(w, "BuildDate:\t%s\n", i.BuildDate) | ||
fmt.Fprintf(w, "GoVersion:\t%s\n", i.GoVersion) | ||
fmt.Fprintf(w, "Compiler:\t%s\n", i.Compiler) | ||
fmt.Fprintf(w, "Platform:\t%s\n", i.Platform) | ||
|
||
w.Flush() // #nosec | ||
return b.String() | ||
} | ||
|
||
// JSONString returns the JSON representation of the version info | ||
func (i *Info) JSONString() (string, error) { | ||
b, err := json.MarshalIndent(i, "", " ") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return string(b), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: fan-control | ||
namespace: fan-control | ||
labels: | ||
app.kubernetes.io/name: fan-control | ||
spec: | ||
selector: | ||
app.kubernetes.io/name: fan-control | ||
ports: | ||
- name: metrics | ||
port: 9001 | ||
protocol: TCP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: fan-control | ||
namespace: monitoring | ||
labels: | ||
app.kubernetes.io/name: fan-control | ||
spec: | ||
namespaceSelector: | ||
matchNames: | ||
- fan-control | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/name: fan-control | ||
endpoints: | ||
- port: metrics |