golang staticcheck

# nvim+golang 개발환경에서 다음 2개의 툴을 사용하고 있었는데,
# golangc-lint : lint
# gopls : hint, staticcheck, hints...
# diagnostics 로 나오는 staticcheck 를 모두 모아 보고 싶어 staticcheck 커맨드를 별도 설치해서 돌려봤다.
# 설치
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck -checks inherit,-ST1005 ./...

# QF(QuickFix)xxx 결과는 보이지 않고, 실제 체크리스트에서 QF 는 없다.
staticcheck -list-checks

# 알고보니 QF 는 nvim,vscode 등의 IDE 환경에서 gopls 로 staticcheck 를 사용시에만 IDE 로 보인다고 한다.
# 참고로 nvim(lazyvim) 에 gopls 설정 참고

# 테스트
# staticcheck 커맨드에선 QF 결과가 없다.
staticcheck ./...
ysoftman.go:7:5: don't use Yoda conditions (ST1017)

# nvim(lazyvim) 에서 <leader> -> x(diagnostics/quickfix) -> x(diagnostics) 보면 QF도 같이 보인다.

# 문제가 있는 라인으로 커서 이동후 <leader> -> c(code) -> a(code action) 으로 수정할 수 있다.
# yoda conditions 수정하기 (https://staticcheck.dev/docs/checks#ST1017)
# golang 에서는 if 내에서 = 로 할당이 안되기 때문에 c++ 처럼 값을 왼쪽에 명시해 할당 실수를 방지하는 스타일로 짜지 않아도 된다. golang 에서도 빌드는 문제 없지만 이런식은 자연스럽지 않다고 요렇게 st 로 정해두고 있다.
# 참고로 스타워즈 yoda 가 어순을 바꿔 말하는데서 유래됐다고 한다.

# 공통 변수에 대해 if / else if 문을 switch 로 수정하기  (https://staticcheck.dev/docs/checks#QF1003)
# switch 로 바꾸면 가독성이 더 좋아 보인다.

nvim taplo toml format error

# nvim(lazyvim)에 .air.toml 처럼 air 이름의 toml 파일을 열면 다음과 같은 diagnostics 에러가 발생한다.
additional properties are not allowed

# 다른 이름의 toml 파일은 문제가 없다.
# lazyvim 에서 기본적으로 toml 파일에 대해 lsp(Language Server Protocol), lint, format 을 위해 taplo(https://github.com/tamasfe/taplo, even better toml) 툴을 설치해 사용한다.
{ import = "lazyvim.plugins.extras.lang.toml" },

# toml 파일을 열면 taplo lsp 프로세스가 생성되어 처리한다.
hwatch -n 1 "ps -ef | rg -i taplo"
/Users/ysoftman/.local/share/nvim/mason/bin/taplo lsp stdio --log-spans

# lsp 사용 정보
:LspInfo

# 해결방법
# nvim-lspconfig > schema 를 비활성화
return {
  {
    "neovim/nvim-lspconfig",
    -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md
    opts = {
      servers = {
        taplo = {
          enabled = true,
          settings = {
            evenBetterToml = {
              -- .air.toml 에서 diagnostics 에러가 발생해 비활성화
              schema = { enabled = false },
              formatter = {
                indentString = "  ",
              },
            },
          },
        },
...

# 참고
# toml 파일들 일괄 포멧팅
fd .toml | ~/.local/share/nvim/mason/bin/taplo format --log-spans

# toml 내용 stdin 입력 포맷팅
cat typos.toml | ~/.local/share/nvim/mason/bin/taplo format -

e2e test dependency(sub) chart

# argo-cd 에서 각 컴포넌트들은 배포(싱크완료) 후 e2e test 가 동작한다.
# 각 컴포넌트별로 e2e test template 를 관리하면 버전등의 관리가 용이하지 않다.
# 그래서 e2e test 를 별도 차트로 구성해 여러 컴포넌트들에서 가져가 사용할 수 있도록 해보자.
# 우선 e2e-test 이름으로 다음과 같이 일반적인 차트를 구성한다.
e2e-test
├── Chart.yaml
├── README.md
├── templates
│   ├── _helpers.tpl
│   ├── e2e-test-job.yaml
│   └── e2e-test-secret.yaml
└── values.yaml

# values.yaml 에 필요한 변수를 설정한다.
enabled: true  # e2e test 사용 여부
job:
  name: "default"
  targetURL: "http://ysoftman.test1.abc"
  # 참고 아래 변수는 e2e 결과 txt파일을 github 저장소에 전송하기 위함이다.
  reportRepository: "https://github.com/ysoftman/e2e-test-report"
  reportFileName: "default-e2e-result.txt"

# e2e-test-job.yaml 은 다음과 같이 PostSync 로 싱크 완료후 job 이 시작될 수 있도록 한다.
apiVersion: batch/v1
kind: Job
metadata:
  generateName: {{ $name }}-e2e-test-
  annotations:
    argocd.argoproj.io/hook: PostSync
    argocd.argoproj.io/compare-options: IgnoreExtraneous
  labels:
    app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
spec:
  ttlSecondsAfterFinished: 600
  successfulJobsHistoryLimit: 5
  failedJobsHistoryLimit: 3
  template:
    spec:
      containers:
... 생략 ...

# 템플릿이 제대로 렌더링 되는지 확인해보자.
helm template .

# 이제 사용하는 컴포넌트의 Chart.yaml 에 dependency 를 설정한다.
# 만약 위 e2e 차트를 github page 나 chartmuseum 로 서빙할 수 있다면 http 로 명시할 수 있다.
# 하지만 다음과 같이 e2e-test 를 같은 저장소에 두면 e2e-test 가 변경될때마다 tgz 를 생성해줘야 한다.
# repository 는 
apiVersion: v2
name: ysoftman-server
description: ysoftman test Server
type: application
version: 0.1.0
appVersion: "0.1.0"
dependencies:
  - name: e2e-test
    version: "1.0.0"
    repository: "file://../e2e-test"

# Chart.yaml 경로에서 다음 명령을 수행하면 ./charts/e2e-test-1.0.0.tgz 와 ./Chart.lock 생성된다.
helm dependency update 

# 다음과 같은 구조가되고, ysoftman-server 가 argocd 로 배포(싱크완료)되면 sub chart 인 e2e-test-1.0.0 이 동작한다.
ysoftman-server
├── Chart.lock
├── Chart.yaml
├── README.md
├── charts
│   └── e2e-test-1.0.0.tgz
├── templates
│   ├── _helper.tpl
│   ├── configmap.yaml
│   ├── deployment.yaml
│   ├── ingress.yaml
│   ├── podmonitor.yaml
│   ├── secret.yaml
│   ├── service.yaml
│   └── servicemonitor.yaml
└── values-dev.yaml

# 참고로 values-dev 에서 sub chart 의 변수를 오버라이딩한다면 다음과 같이 sub chart 이름을 최상위로 명시해야한다.
e2e-test:
  enabled: true
  job:
    name: "ysoftman-server"
    targetURL: "http://ysoftman.test2.abc"
    reportRepository: "https://github.com/ysoftman/e2e-test-report"
    reportFileName: "ysoftman-server-e2e-result.txt"