Skip to content

Commit 7b3a6bd

Browse files
Evsyukov DenisCopilot
andauthored
refactor: simplify jq filter initialization and remove unused libpath (#743)
Signed-off-by: Evsyukov Denis <denis.evsyukov@flant.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 80bd0dd commit 7b3a6bd

File tree

21 files changed

+190
-200
lines changed

21 files changed

+190
-200
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,11 @@ jobs:
3030
go mod download
3131
echo -n "Go modules unpacked size is: " && du -sh $HOME/go/pkg/mod
3232
33-
- name: Download prebuilt libjq static libraries
34-
run: |
35-
curl -sSfL https://github.com/flant/libjq-go/releases/download/jq-b6be13d5-0/libjq-glibc-amd64.tgz | tar zxf -
36-
3733
- name: Build binary
3834
run: |
39-
export CGO_ENABLED=1
40-
export CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/include"
41-
export CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/lib"
4235
export GOOS=linux
4336
44-
go build -tags use_libjq ./cmd/shell-operator
37+
go build ./cmd/shell-operator
4538
4639
# MacOS build works fine because jq package already has static libraries.
4740
# Windows build requires jq compilation, this should be done in libjq-go.

.github/workflows/tests-labeled.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ jobs:
8787
go mod download
8888
echo -n "Go modules unpacked size is: " && du -sh $HOME/go/pkg/mod
8989
90-
- name: Download prebuilt libjq static libraries
91-
run: |
92-
curl -sSfL https://github.com/flant/libjq-go/releases/download/jq-b6be13d5-0/libjq-glibc-amd64.tgz | tar zxf -
93-
9490
- name: Install ginkgo
9591
run: |
9692
go install github.com/onsi/ginkgo/ginkgo
@@ -109,9 +105,6 @@ jobs:
109105
env:
110106
CLUSTER_NAME: ${{ matrix.cluster_name }}
111107
run: |
112-
export CGO_ENABLED=1
113-
export CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/include"
114-
export CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/lib"
115108
export GOOS=linux
116109
117110
ginkgo \

.github/workflows/tests.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,8 @@ jobs:
3333
go mod download
3434
echo -n "Go modules unpacked size is: " && du -sh $HOME/go/pkg/mod
3535
36-
- name: Download prebuilt libjq static libraries
37-
run: |
38-
curl -sSfL https://github.com/flant/libjq-go/releases/download/jq-b6be13d5-0/libjq-glibc-amd64.tgz | tar zxf -
39-
4036
- name: Run unit tests
4137
run: |
42-
export CGO_ENABLED=1
43-
export CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/include"
44-
export CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/lib"
4538
export GOOS=linux
4639
4740
go test \

Dockerfile

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Prebuilt libjq.
2-
FROM --platform=${TARGETPLATFORM:-linux/amd64} flant/jq:b6be13d5-musl as libjq
3-
41
# Go builder.
52
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.23-alpine3.21 AS builder
63

@@ -12,15 +9,10 @@ ADD go.mod go.sum /app/
129
WORKDIR /app
1310
RUN go mod download
1411

15-
COPY --from=libjq /libjq /libjq
1612
ADD . /app
1713

18-
RUN CGO_ENABLED=1 \
19-
CGO_CFLAGS="-I/libjq/include" \
20-
CGO_LDFLAGS="-L/libjq/lib" \
21-
GOOS=linux \
22-
go build -ldflags="-linkmode external -extldflags '-static' -s -w -X 'github.com/flant/shell-operator/pkg/app.Version=$appVersion'" \
23-
-tags use_libjq \
14+
RUN GOOS=linux \
15+
go build -ldflags="-s -w -X 'github.com/flant/shell-operator/pkg/app.Version=$appVersion'" \
2416
-o shell-operator \
2517
./cmd/shell-operator
2618

@@ -35,10 +27,9 @@ RUN apk --no-cache add ca-certificates bash sed tini && \
3527
mkdir /hooks
3628
ADD frameworks/shell /frameworks/shell
3729
ADD shell_lib.sh /
38-
COPY --from=libjq /bin/jq /usr/bin
3930
COPY --from=builder /app/shell-operator /
4031
WORKDIR /
41-
ENV SHELL_OPERATOR_HOOKS_DIR /hooks
42-
ENV LOG_TYPE json
32+
ENV SHELL_OPERATOR_HOOKS_DIR=/hooks
33+
ENV LOG_TYPE=json
4334
ENTRYPOINT ["/sbin/tini", "--", "/shell-operator"]
4435
CMD ["start"]

cmd/shell-operator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
// print version
3434
kpApp.Command("version", "Show version.").Action(func(_ *kingpin.ParseContext) error {
3535
fmt.Printf("%s %s\n", app.AppName, app.Version)
36-
fl := jq.NewFilter(app.JqLibraryPath)
36+
fl := jq.NewFilter()
3737
fmt.Println(fl.FilterInfo())
3838
return nil
3939
})

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.23.1
55
require (
66
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241205040953-7b376bae249c
77
github.com/flant/kube-client v1.2.2
8-
github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee // branch: master
98
github.com/go-chi/chi/v5 v5.2.1
109
github.com/go-openapi/spec v0.19.8
1110
github.com/go-openapi/strfmt v0.19.5
@@ -36,6 +35,7 @@ replace github.com/go-openapi/validate => github.com/flant/go-openapi-validate v
3635
require (
3736
github.com/deckhouse/module-sdk v0.2.0
3837
github.com/gojuno/minimock/v3 v3.4.5
38+
github.com/itchyny/gojq v0.12.17
3939
)
4040

4141
require (
@@ -71,6 +71,7 @@ require (
7171
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
7272
github.com/hashicorp/errwrap v1.1.0 // indirect
7373
github.com/imdario/mergo v0.3.16 // indirect
74+
github.com/itchyny/timefmt-go v0.1.6 // indirect
7475
github.com/jonboulle/clockwork v0.4.0 // indirect
7576
github.com/josharian/intern v1.0.0 // indirect
7677
github.com/json-iterator/go v1.1.12 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ github.com/flant/go-openapi-validate v0.19.12-flant.0 h1:xk6kvc9fHKMgUdB6J7kbpbL
4141
github.com/flant/go-openapi-validate v0.19.12-flant.0/go.mod h1:Rzou8hA/CBw8donlS6WNEUQupNvUZ0waH08tGe6kAQ4=
4242
github.com/flant/kube-client v1.2.2 h1:27LBs+PKJEFnkQXjPU9eIps7a7iyI13AKcSYj897DCU=
4343
github.com/flant/kube-client v1.2.2/go.mod h1:eMa3aJ6V1PRWSQ/RCROkObDpY4S74uM84SJS4G/LINg=
44-
github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee h1:evii83J+/6QGNvyf6tjQ/p27DPY9iftxIBb37ALJRTg=
45-
github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee/go.mod h1:f+REaGl/+pZR97rbTcwHEka/MAipoQQ2Mc0iQUj4ak0=
4644
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
4745
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
4846
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
@@ -176,6 +174,10 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
176174
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
177175
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
178176
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
177+
github.com/itchyny/gojq v0.12.17 h1:8av8eGduDb5+rvEdaOO+zQUjA04MS0m3Ps8HiD+fceg=
178+
github.com/itchyny/gojq v0.12.17/go.mod h1:WBrEMkgAfAGO1LUcGOckBl5O726KPp+OlkKug0I/FEY=
179+
github.com/itchyny/timefmt-go v0.1.6 h1:ia3s54iciXDdzWzwaVKXZPbiXzxxnv1SPGFfM/myJ5Q=
180+
github.com/itchyny/timefmt-go v0.1.6/go.mod h1:RRDZYC5s9ErkjQvTvvU7keJjxUYzIISJGxm9/mAERQg=
179181
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
180182
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
181183
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=

pkg/app/app.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ func DefineStartCommandFlags(kpApp *kingpin.Application, cmd *kingpin.CmdClause)
134134
DefineKubeClientFlags(cmd)
135135
DefineValidatingWebhookFlags(cmd)
136136
DefineConversionWebhookFlags(cmd)
137-
DefineJqFlags(cmd)
138137
DefineLoggingFlags(cmd)
139138
DefineDebugFlags(kpApp, cmd)
140139
}

pkg/app/jq.go

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

pkg/filter/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package filter
22

33
type Filter interface {
4-
ApplyFilter(filterStr string, data []byte) (string, error)
4+
ApplyFilter(filterStr string, data map[string]any) (map[string]any, error)
55
FilterInfo() string
66
}

0 commit comments

Comments
 (0)