Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

refactor: split cr-discovery into multiple modules #1151

Merged
merged 2 commits into from
Feb 2, 2024
Merged
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
15 changes: 14 additions & 1 deletion .github/workflows/reusable-build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ jobs:
push: ${{ inputs.push }}
timestamp: ${{ needs.timestamp.outputs.timestamp }}

vmclarity-cr-discovery-server:
needs:
- images
- timestamp
uses: ./.github/workflows/build-and-push-component.yaml
with:
dockerfile: Dockerfile.cr-discovery-server
image_name: ${{ needs.images.outputs.cr-discovery-server-image }}
image_tag: ${{ inputs.image_tag }}
push: ${{ inputs.push }}
timestamp: ${{ needs.timestamp.outputs.timestamp }}

post-images:
if: github.event_name == 'pull_request' && inputs.post_image_tags
runs-on: ubuntu-latest
Expand All @@ -117,6 +129,7 @@ jobs:
- vmclarity-ui-backend
- vmclarity-ui
- vmclarity-cli
- vmclarity-cr-discovery-server
steps:
- name: Post comment with image tags
uses: marocchino/sticky-pull-request-comment@v2
Expand All @@ -134,4 +147,4 @@ jobs:
* `${{ format('{0}:{1}', needs.images.outputs.ui-backend-image, inputs.image_tag) }}`
* `${{ format('{0}:{1}', needs.images.outputs.ui-image, inputs.image_tag) }}`
* `${{ format('{0}:{1}', needs.images.outputs.cli-image, inputs.image_tag) }}`

* `${{ format('{0}:{1}', needs.images.outputs.cr-discovery-server-image, inputs.image_tag) }}`
5 changes: 5 additions & 0 deletions .github/workflows/reusable-image-names.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ on:
cli-image:
value: ${{ jobs.images.outputs.cli-image }}
description: 'Name of the container image for VMClarity CLI'
cr-discovery-server-image:
value: ${{ jobs.images.outputs.cr-discovery-server-image }}
description: 'Name of the container image for VMClarity ContainerRuntime Discovery Server'

jobs:
images:
Expand All @@ -39,6 +42,7 @@ jobs:
ui-backend-image: ${{ steps.images.outputs.ui-backend-image }}
ui-image: ${{ steps.images.outputs.ui-image }}
cli-image: ${{ steps.images.outputs.cli-image }}
cr-discovery-server-image: ${{ steps.images.outputs.cr-discovery-server-image }}
steps:
- name: Set container image names
id: images
Expand All @@ -63,4 +67,5 @@ jobs:
echo "ui-backend-image=${registry}/vmclarity-ui-backend${suffix}"
echo "ui-image=${registry}/vmclarity-ui${suffix}"
echo "cli-image=${registry}/vmclarity-cli${suffix}"
echo "cr-discovery-server-image=${registry}/vmclarity-cr-discovery-server${suffix}"
} >> "$GITHUB_OUTPUT"
4 changes: 2 additions & 2 deletions Dockerfile.cr-discovery-server
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN --mount=type=cache,id=${TARGETPLATFORM}-apt,target=/var/cache/apt,sharing=lo
gcc \
libc6-dev

WORKDIR /build
WORKDIR /build/containerruntimediscovery/server

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
Expand All @@ -35,7 +35,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
-X 'github.com/openclarity/vmclarity/utils/version.Version=${VERSION}' \
-X 'github.com/openclarity/vmclarity/utils/version.CommitHash=${COMMIT_HASH}' \
-X 'github.com/openclarity/vmclarity/utils/version.BuildTimestamp=${BUILD_TIMESTAMP}'" \
-o /bin/vmclarity-cr-discovery-server cmd/vmclarity-cr-discovery-server/main.go
-o /bin/vmclarity-cr-discovery-server cmd/main.go

RUN xx-verify /bin/vmclarity-cr-discovery-server

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ bin/vmclarity-ui-backend: $(shell find api) $(shell find uibackend/server/cmd) $
-X 'github.com/openclarity/vmclarity/utils/version.BuildTimestamp=$(BUILD_TIMESTAMP)'" \
-o ../../$@ cmd/main.go

bin/vmclarity-cr-discovery-server: $(shell find api) $(shell find cmd/vmclarity-cr-discovery-server) $(shell find pkg) go.mod go.sum | $(BIN_DIR)
go build -race -o bin/vmclarity-cr-discovery-server cmd/vmclarity-cr-discovery-server/main.go
bin/vmclarity-cr-discovery-server: $(shell find api) $(shell find containerruntimediscovery/server/cmd) $(shell find containerruntimediscovery/server/pkg) containerruntimediscovery/server/go.mod containerruntimediscovery/server/go.sum | $(BIN_DIR)
cd containerruntimediscovery/server && go build -race -ldflags="-s -w \
-X 'github.com/openclarity/vmclarity/utils/version.Version=$(VERSION)' \
-X 'github.com/openclarity/vmclarity/utils/version.CommitHash=$(COMMIT_HASH)' \
-X 'github.com/openclarity/vmclarity/utils/version.BuildTimestamp=$(BUILD_TIMESTAMP)'" \
-o ../../$@ cmd/main.go

.PHONY: clean
clean: clean-ui clean-go ## Clean all build artifacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package containerruntimediscovery
package client

import (
"context"
Expand All @@ -23,7 +23,7 @@ import (
"net/http"

apitypes "github.com/openclarity/vmclarity/api/types"
"github.com/openclarity/vmclarity/pkg/containerruntimediscovery/types"
"github.com/openclarity/vmclarity/containerruntimediscovery/types"
)

type Client struct {
Expand All @@ -50,7 +50,7 @@ func (c *Client) GetImages(ctx context.Context) ([]apitypes.ContainerImageInfo,

switch resp.StatusCode {
case http.StatusOK:
var lir ListImagesResponse
var lir types.ListImagesResponse
decoder := json.NewDecoder(resp.Body)
err := decoder.Decode(&lir)
if err != nil {
Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *Client) GetContainers(ctx context.Context) ([]apitypes.ContainerInfo, e

switch resp.StatusCode {
case http.StatusOK:
var lcr ListContainersResponse
var lcr types.ListContainersResponse
decoder := json.NewDecoder(resp.Body)
err := decoder.Decode(&lcr)
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions containerruntimediscovery/client/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module github.com/openclarity/vmclarity/containerruntimediscovery/client

go 1.21.4

require (
github.com/openclarity/vmclarity/api/types v0.0.0-00010101000000-000000000000
github.com/openclarity/vmclarity/containerruntimediscovery/types v0.0.0-00010101000000-000000000000
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/deepmap/oapi-codegen/v2 v2.1.0 // indirect
github.com/getkin/kin-openapi v0.123.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/swag v0.22.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace (
github.com/openclarity/vmclarity/api/types => ../../api/types
github.com/openclarity/vmclarity/containerruntimediscovery/types => ../types
)
64 changes: 64 additions & 0 deletions containerruntimediscovery/client/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deepmap/oapi-codegen/v2 v2.1.0 h1:I/NMVhJCtuvL9x+S2QzZKpSjGi33oDZwPRdemvOZWyQ=
github.com/deepmap/oapi-codegen/v2 v2.1.0/go.mod h1:R1wL226vc5VmCNJUvMyYr3hJMm5reyv25j952zAVXZ8=
github.com/getkin/kin-openapi v0.123.0 h1:zIik0mRwFNLyvtXK274Q6ut+dPh6nlxBp0x7mNrPhs8=
github.com/getkin/kin-openapi v0.123.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM=
github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q=
github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs=
github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicbw=
github.com/go-openapi/swag v0.22.8/go.mod h1:6QT22icPLEqAM/z/TChgb4WAveCHF92+2gF0CNjHpPI=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd
package main

import (
"context"
Expand All @@ -27,7 +27,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/openclarity/vmclarity/pkg/containerruntimediscovery"
server "github.com/openclarity/vmclarity/containerruntimediscovery/server/pkg"
"github.com/openclarity/vmclarity/utils/log"
)

Expand All @@ -46,15 +46,15 @@ var (
ctx := cmd.Context()
ctx = log.SetLoggerForContext(ctx, logger)

discoverer, err := containerruntimediscovery.NewDiscoverer(ctx)
discoverer, err := server.NewDiscoverer(ctx)
if err != nil {
return fmt.Errorf("unable to create discoverer: %w", err)
}

abortCtx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer cancel()

crds := containerruntimediscovery.NewContainerRuntimeDiscoveryServer(discoverer)
crds := server.NewContainerRuntimeDiscoveryServer(discoverer)
crds.Serve(abortCtx, listenAddr)

logger.Infof("Server started listening on %s...", listenAddr)
Expand All @@ -77,12 +77,6 @@ var (
}
)

// Execute executes the root command.
func Execute() error {
// nolint: wrapcheck
return rootCmd.Execute()
}

func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(
Expand All @@ -99,3 +93,7 @@ func init() {
func initConfig() {
viper.AutomaticEnv()
}

func main() {
cobra.CheckErr(rootCmd.Execute())
}
Loading
Loading