Skip to content

Commit 87223bc

Browse files
farr-slmnSuleyman Farrakhov
andauthored
Go hooks (#46)
- Migrated from python to go hooks - Fixed documentation --------- Co-authored-by: Suleyman Farrakhov <[email protected]>
1 parent 4060a29 commit 87223bc

19 files changed

+778
-336
lines changed

.werf/defines/image-build.tmpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{- define "image-build.build" }}
2+
{{- if ne $.SVACE_ENABLED "false" }}
3+
svace build --init --clear-build-dir {{ .BuildCommand }}
4+
attempt=0
5+
retries=5
6+
success=0
7+
set +e
8+
while [[ $attempt -lt $retries ]]; do
9+
ssh -o ConnectTimeout=10 -o ServerAliveInterval=10 -o ServerAliveCountMax=12 {{ $.SVACE_ANALYZE_SSH_USER }}@{{ $.SVACE_ANALYZE_HOST }} mkdir -p /svace-analyze/{{ $.Commit.Hash }}/{{ $.ProjectName }}/.svace-dir
10+
rsync -zr --timeout=10 --compress-choice=zstd --partial --append-verify .svace-dir {{ $.SVACE_ANALYZE_SSH_USER }}@{{ $.SVACE_ANALYZE_HOST }}:/svace-analyze/{{ $.Commit.Hash }}/{{ $.ProjectName }}/ && success=1 && break
11+
sleep 10
12+
attempt=$((attempt + 1))
13+
done
14+
set -e
15+
[[ $success == 1 ]] && rm -rf .svace-dir || exit 1
16+
{{ .BuildCommand }}
17+
{{- else }}
18+
{{ .BuildCommand }}
19+
{{- end }}
20+
{{- end }}

.werf/stages/bundle.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@ import:
1212
- version.json
1313
after: setup
1414
# Rendering .werf/stages/python-deps.yaml is required! Comment out if not needed.
15-
- image: python-dependencies
16-
add: /lib/python/dist
17-
to: /lib/python/dist
18-
after: setup
15+
# - image: python-dependencies
16+
# add: /lib/python/dist
17+
# to: /lib/python/dist
18+
# after: setup
1919
# Uncomment if you use batch hooks built with batch-go.yaml werf job
2020
# - image: batch-hooks
2121
# add: /usr/local/bin/batchhooks
2222
# to: /hooks/batchhooks
2323
# after: setup
24+
- image: go-hooks-artifact
25+
add: /go-hooks
26+
to: /hooks/go-hooks
27+
after: setup
2428
git:
2529
- add: /
2630
to: /
2731
# Uncomment if you use batch-go.yaml werf job
28-
# excludePaths:
29-
# - hooks/batch # exclude sources
32+
excludePaths:
33+
- hooks/batch # exclude sources
3034
includePaths:
3135
- .helmignore
3236
- docs

.werf/stages/images.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
{{- $ImagesBuildFiles := .Files.Glob "images/*/{Dockerfile,werf.inc.yaml}" }}
2+
{{- $Root := . }}
23

34
{{- range $path, $content := $ImagesBuildFiles }}
45
{{- $ctx := dict }}
56
{{- $_ := set $ctx "ImageName" ($path | split "/")._1 }}
67
{{- $_ := set $ctx "ImagePath" (printf "/images/%s" $ctx.ImageName) }}
78
{{- $_ := set $ctx "ModuleNamePrefix" "" }}
8-
{{- $_ := set $ctx "GOPROXY" "https://proxy.golang.org,direct" }}
9-
{{- $_ := set $ctx "SOURCE_REPO" "false" }}
9+
{{- $_ := set $ctx "ModuleDir" "/" }}
10+
{{- $_ := set $ctx "GOPROXY" $Root.GOPROXY }}
11+
{{- $_ := set $ctx "SOURCE_REPO" $Root.SOURCE_REPO }}
12+
{{- $_ := set $ctx "DistroPackagesProxy" $Root.DistroPackagesProxy }}
13+
{{- $_ := set $ctx "Commit" $Root.Commit }}
14+
{{- $_ := set $ctx "ProjectName" (printf "%s/%s" $Root.MODULES_MODULE_NAME $ctx.ImageName ) }}
15+
{{- $_ := set $ctx "SVACE_IMAGE_SUFFIX" $Root.SVACE_IMAGE_SUFFIX }}
16+
{{- $_ := set $ctx "SVACE_ENABLED" $Root.SVACE_ENABLED }}
17+
{{- $_ := set $ctx "SVACE_ANALYZE_SSH_USER" $Root.SVACE_ANALYZE_SSH_USER }}
18+
{{- $_ := set $ctx "SVACE_ANALYZE_HOST" $Root.SVACE_ANALYZE_HOST }}
19+
{{- $_ := set $ctx "STRONGHOLD_EDITION" $Root.STRONGHOLD_EDITION }}
1020
{{- $_ := set $ctx "Files" $.Files }}
1121
---
1222
{{- /* For Dockerfile just render it from the folder. */ -}}

.werf/stages/python-deps.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/USAGE_RU.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ spec:
4848
WoR9b11eYfyrnKCYoSqBoi2dwkCkV1a0GN9vStwiBnKnAmV3B8B5yMnSjmp+42gt
4949
o2SYzqM=
5050
-----END CERTIFICATE-----
51+
connectionConfiguration: Manual
5152
```
5253

5354
**Крайне рекомендуется задавать переменную `caCert`. Если она не задана, будет использовано содержимое системного ca-certificates.**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Flant JSC
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package api
5+
6+
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
type SecretStoreImportSpec struct {
11+
AuthPath string `json:"authPath,omitempty"`
12+
Namespace string `json:"namespace,omitempty"`
13+
Address string `json:"address,omitempty"`
14+
CACert string `json:"caCert,omitempty"`
15+
Audience string `json:"audience,omitempty"`
16+
SkipTLSVerify bool `json:"skipTLSVerify,omitempty"`
17+
Files []*struct {
18+
Name string `json:"name,omitempty"`
19+
Source struct {
20+
Key string `json:"key,omitempty"`
21+
Path string `json:"path,omitempty"`
22+
} `json:"source,omitempty"`
23+
} `json:"files,omitempty"`
24+
Role string `json:"role,omitempty"`
25+
Type string `json:"type,omitempty"`
26+
}
27+
28+
type SecretStoreImport struct {
29+
metav1.TypeMeta `json:",inline"`
30+
metav1.ObjectMeta `json:"metadata,omitempty"`
31+
Spec SecretStoreImportSpec `json:"spec,omitempty"`
32+
}

hooks/batch/common/ensure_crds.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Flant JSC
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package common
5+
6+
import (
7+
ensure_crds "github.com/deckhouse/module-sdk/common-hooks/ensure_crds"
8+
)
9+
10+
var _ = ensure_crds.RegisterEnsureCRDsHookEM("../crds/*.yaml")
11+
var _ = ensure_crds.RegisterEnsureCRDsHookEM("../crds/*/*.yaml")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Flant JSC
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package common
5+
6+
import (
7+
"fmt"
8+
"secrets-store-integration-hook/consts"
9+
10+
tlscertificate "github.com/deckhouse/module-sdk/common-hooks/tls-certificate"
11+
)
12+
13+
var _ = tlscertificate.RegisterInternalTLSHookEM(tlscertificate.GenSelfSignedTLSHookConf{
14+
CN: consts.WebhookName,
15+
TLSSecretName: fmt.Sprintf("%s-tls", consts.WebhookName),
16+
Namespace: consts.ModuleNamespace,
17+
CommonCACanonicalName: "Deckhouse",
18+
SANs: tlscertificate.DefaultSANs([]string{
19+
fmt.Sprintf("%s.%s.svc", consts.WebhookName, consts.ModuleNamespace),
20+
}),
21+
FullValuesPathPrefix: fmt.Sprintf("%s.internal.webhookCert", consts.DotValuesModuleName),
22+
})

hooks/batch/consts/consts.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Flant JSC
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package consts
5+
6+
const (
7+
ModuleName string = "secrets-store-integration"
8+
ModuleNamespace string = "d8-secrets-store-integration"
9+
DotValuesModuleName string = "secretsStoreIntegration"
10+
WebhookName string = "vault-secrets-webhook"
11+
SSIKind string = "SecretsStoreImport"
12+
SSIapiVersion string = "deckhouse.io/v1alpha1"
13+
SPCKind string = "SecretProviderClass"
14+
SPCapiVersion string = "secrets-store.csi.x-k8s.io/v1"
15+
)

hooks/batch/go.mod

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
module secrets-store-integration-hook
2+
3+
go 1.23.10
4+
5+
toolchain go1.24.6
6+
7+
require (
8+
github.com/deckhouse/module-sdk v0.3.6
9+
k8s.io/apimachinery v0.30.11
10+
sigs.k8s.io/secrets-store-csi-driver v1.5.3
11+
)
12+
13+
require (
14+
github.com/DataDog/gostackparse v0.7.0 // indirect
15+
github.com/beorn7/perks v1.0.1 // indirect
16+
github.com/caarlos0/env/v11 v11.3.1 // indirect
17+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
18+
github.com/cloudflare/cfssl v1.6.5 // indirect
19+
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
20+
github.com/davecgh/go-spew v1.1.1 // indirect
21+
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20250424095005-9ab587d01d7a // indirect
22+
github.com/docker/cli v24.0.0+incompatible // indirect
23+
github.com/docker/distribution v2.8.2+incompatible // indirect
24+
github.com/docker/docker v25.0.6+incompatible // indirect
25+
github.com/docker/docker-credential-helpers v0.7.0 // indirect
26+
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
27+
github.com/ettle/strcase v0.2.0 // indirect
28+
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
29+
github.com/fsnotify/fsnotify v1.7.0 // indirect
30+
github.com/go-logr/logr v1.4.2 // indirect
31+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
32+
github.com/go-openapi/jsonreference v0.20.2 // indirect
33+
github.com/go-openapi/swag v0.22.3 // indirect
34+
github.com/gogo/protobuf v1.3.2 // indirect
35+
github.com/gojuno/minimock/v3 v3.4.5 // indirect
36+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
37+
github.com/golang/protobuf v1.5.4 // indirect
38+
github.com/google/certificate-transparency-go v1.1.7 // indirect
39+
github.com/google/gnostic-models v0.6.8 // indirect
40+
github.com/google/go-cmp v0.7.0 // indirect
41+
github.com/google/go-containerregistry v0.17.0 // indirect
42+
github.com/google/gofuzz v1.2.0 // indirect
43+
github.com/google/uuid v1.6.0 // indirect
44+
github.com/hashicorp/errwrap v1.0.0 // indirect
45+
github.com/hashicorp/go-multierror v1.1.1 // indirect
46+
github.com/imdario/mergo v0.3.16 // indirect
47+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
48+
github.com/jmoiron/sqlx v1.3.5 // indirect
49+
github.com/jonboulle/clockwork v0.4.0 // indirect
50+
github.com/josharian/intern v1.0.0 // indirect
51+
github.com/json-iterator/go v1.1.12 // indirect
52+
github.com/klauspost/compress v1.16.5 // indirect
53+
github.com/mailru/easyjson v0.7.7 // indirect
54+
github.com/mitchellh/go-homedir v1.1.0 // indirect
55+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
56+
github.com/modern-go/reflect2 v1.0.2 // indirect
57+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
58+
github.com/opencontainers/go-digest v1.0.0 // indirect
59+
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
60+
github.com/pelletier/go-toml v1.9.3 // indirect
61+
github.com/pkg/errors v0.9.1 // indirect
62+
github.com/pmezard/go-difflib v1.0.0 // indirect
63+
github.com/prometheus/client_golang v1.19.0 // indirect
64+
github.com/prometheus/client_model v0.5.0 // indirect
65+
github.com/prometheus/common v0.48.0 // indirect
66+
github.com/prometheus/procfs v0.12.0 // indirect
67+
github.com/sirupsen/logrus v1.9.3 // indirect
68+
github.com/spf13/cobra v1.9.1 // indirect
69+
github.com/spf13/pflag v1.0.6 // indirect
70+
github.com/sylabs/oci-tools v0.7.0 // indirect
71+
github.com/tidwall/gjson v1.18.0 // indirect
72+
github.com/tidwall/match v1.1.1 // indirect
73+
github.com/tidwall/pretty v1.2.0 // indirect
74+
github.com/vbatts/tar-split v0.11.3 // indirect
75+
github.com/weppos/publicsuffix-go v0.30.0 // indirect
76+
github.com/zmap/zcrypto v0.0.0-20230310154051-c8b263fd8300 // indirect
77+
github.com/zmap/zlint/v3 v3.5.0 // indirect
78+
golang.org/x/crypto v0.36.0 // indirect
79+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
80+
golang.org/x/net v0.38.0 // indirect
81+
golang.org/x/oauth2 v0.27.0 // indirect
82+
golang.org/x/sync v0.12.0 // indirect
83+
golang.org/x/sys v0.31.0 // indirect
84+
golang.org/x/term v0.30.0 // indirect
85+
golang.org/x/text v0.23.0 // indirect
86+
golang.org/x/time v0.8.0 // indirect
87+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
88+
google.golang.org/protobuf v1.33.0 // indirect
89+
gopkg.in/inf.v0 v0.9.1 // indirect
90+
gopkg.in/yaml.v2 v2.4.0 // indirect
91+
gopkg.in/yaml.v3 v3.0.1 // indirect
92+
k8s.io/api v0.30.11 // indirect
93+
k8s.io/apiextensions-apiserver v0.30.11 // indirect
94+
k8s.io/client-go v0.30.11 // indirect
95+
k8s.io/klog/v2 v2.130.1 // indirect
96+
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
97+
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
98+
sigs.k8s.io/controller-runtime v0.18.7 // indirect
99+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
100+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
101+
sigs.k8s.io/yaml v1.4.0 // indirect
102+
)

0 commit comments

Comments
 (0)