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

Jeremymv2/k8sapi #10

Closed
wants to merge 6 commits into from
Closed
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
26 changes: 26 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: golangci-lint
on:
push:
branches:
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: k8s/migration
2 changes: 2 additions & 0 deletions appliance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
k3s.yaml
.vagrant/*
19 changes: 19 additions & 0 deletions appliance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Appliance VM

This VM is built on flatcar linux and k3s.

## Quickstart

The following commands are for local development using Vagrant.

Note: The VM is provisioned with a 2nd NIC (eth1) with an IP of 192.168.56.10. If you need a different
IP provisioned, you can set it with `export K8S_IP=x.x.x.x` before running vagrant up.

```bash
vagrant up
vagrant ssh control1 -- -t 'sudo cat /etc/rancher/k3s/k3s.yaml' > k3s.yaml
export KUBECONFIG=$PWD/k3s.yaml
k get nodes
NAME STATUS ROLES AGE VERSION
control1 Ready control-plane,etcd,master 8m19s v1.30.0+k3s1
```
45 changes: 45 additions & 0 deletions appliance/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
ENV["TERM"] = "xterm-256color"
ENV["LC_ALL"] = "en_US.UTF-8"

K8S_IP = ENV["K8S_IP"] || "192.168.56.10"

$script = <<-SCRIPT
curl -sfL https://get.k3s.io | \
K3S_KUBECONFIG_MODE="640" \
INSTALL_K3S_VERSION="v1.30.0+k3s1" \
INSTALL_K3S_EXEC="server \
--node-external-ip #{K8S_IP} \
--node-ip #{K8S_IP} \
--bind-address #{K8S_IP} \
--advertise-address #{K8S_IP} \
--flannel-iface eth1 \
--disable servicelb \
--disable traefik \
--disable local-storage \
--cluster-init" \
sh -
SCRIPT

Vagrant.configure("2") do |config|
# General configuration
config.vm.box = "https://alpha.release.flatcar-linux.net/amd64-usr/current/flatcar_production_vagrant.box"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vbguest.auto_update = false
config.ssh.username = 'core'
config.ssh.insert_key = true

config.vm.provider :virtualbox do |v|
v.check_guest_additions = false
v.functional_vboxsf = false
v.memory = 8192
v.cpus = 2
v.linked_clone = true
end

config.vm.define "control1" do |control1|
control1.vm.hostname = "control1"
control1.vm.network "private_network", ip: "#{K8S_IP}"
end

config.vm.provision "shell", inline: $script
end
3 changes: 3 additions & 0 deletions k8s/migration/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
27 changes: 27 additions & 0 deletions k8s/migration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin/*
Dockerfile.cross

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Go workspace file
go.work

# Kubernetes Generated files - skip generated files, except for vendored files
!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~
203 changes: 203 additions & 0 deletions k8s/migration/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
linters-settings:
errcheck:
exclude-functions:
- 'fmt:[FS]?[Pp]rint*'
- fmt.Fprintf
depguard:
rules:
logger:
deny:
# logging is allowed only by logutils.Log,
- pkg: "github.com/sirupsen/logrus"
desc: logging is allowed only by logutils.Log.
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package.
- pkg: "github.com/instana/testify"
desc: It's a fork of github.com/stretchr/testify.
files:
# logrus is allowed to use only in logutils package.
- "!**/pkg/logutils/**.go"
dupl:
threshold: 100
funlen:
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
gocyclo:
min-complexity: 15
godox:
keywords:
- FIXME
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
goimports:
local-prefixes: github.com/golangci/golangci-lint
mnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '2'
- '3'
ignored-functions:
- strings.SplitN
govet:
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
enable:
- nilness
- shadow
errorlint:
asserts: false
lll:
line-length: 140
misspell:
locale: US
ignore-words:
- "importas" # linter name
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
revive:
rules:
- name: indent-error-flow
- name: unexported-return
disabled: true
- name: unused-parameter
- name: unused-receiver

linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- errorlint
- exportloopref
- funlen
- gocheckcompilerdirectives
# - gochecknoinits
- goconst
- gocritic
- gocyclo
- godox
- gofmt
- goimports
- mnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- revive
- staticcheck
- stylecheck
- testifylint
- unconvert
- unparam
- unused
- whitespace

# This list of linters is not a recommendation (same thing for all this configuration file).
# We intentionally use a limited set of linters.
# See the comment on top of this file.

issues:
exclude-rules:
- path: (.+)_test\.go
linters:
- dupl
- mnd
- lll

# The logic of creating a linter is similar between linters, it's not duplication.
- path: pkg/golinters
linters:
- dupl

# Deprecated configuration options.
- path: pkg/commands/run.go
linters: [staticcheck]
text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead."

# Deprecated linter options.
- path: pkg/golinters/errcheck/errcheck.go
linters: [staticcheck]
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
- path: pkg/golinters/errcheck/errcheck.go
linters: [staticcheck]
text: "SA1019: errCfg.Ignore is deprecated: use ExcludeFunctions instead"
- path: pkg/golinters/govet/govet.go
linters: [staticcheck]
text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside Enable."
- path: pkg/golinters/godot/godot.go
linters: [staticcheck]
text: "SA1019: settings.CheckAll is deprecated: use Scope instead"
- path: pkg/golinters/gci/gci.go
linters: [staticcheck]
text: "SA1019: settings.LocalPrefixes is deprecated: use Sections instead."
- path: pkg/golinters/mnd/mnd.go
linters: [staticcheck]
text: "SA1019: settings.Settings is deprecated: use root level settings instead."
- path: pkg/golinters/mnd/mnd.go
linters: [staticcheck]
text: "SA1019: config.GoMndSettings is deprecated: use MndSettings."

# Related to `run.go`, it cannot be removed.
- path: pkg/golinters/gofumpt/gofumpt.go
linters: [staticcheck]
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
- path: pkg/golinters/internal/staticcheck_common.go
linters: [staticcheck]
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead."
- path: pkg/lint/lintersdb/manager.go
linters: [staticcheck]
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."

# Based on existing code, the modifications should be limited to make maintenance easier.
- path: pkg/golinters/unused/unused.go
linters: [gocritic]
text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)"

exclude-dirs:
- test # test files
- internal/cache # extracted from Go code
- internal/renameio # extracted from Go code
- internal/robustio # extracted from Go code

run:
timeout: 5m
33 changes: 33 additions & 0 deletions k8s/migration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Build the manager binary
FROM golang:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
Loading
Loading