Skip to content
Open
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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/kubescape/k8s-interface v0.0.206
github.com/ncw/directio v1.0.5
github.com/olvrng/ujson v1.1.0
github.com/puzpuzpuz/xsync/v2 v2.4.1
github.com/spf13/afero v1.15.0
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.20.1
Expand Down Expand Up @@ -221,3 +220,5 @@ require (
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)

replace k8s.io/apiserver => github.com/matthyx/apiserver v0.0.0-20260603054931-54c588143d7b
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/matthyx/apiserver v0.0.0-20260603054931-54c588143d7b h1:v4QhVueYEL9wiUPaKLnedbQDJbjOBISoURY0V3cExqQ=
github.com/matthyx/apiserver v0.0.0-20260603054931-54c588143d7b/go.mod h1:QUy1U4+PrzbJaM3XGu2tQ7U9A4udRRo5cyxkFX0GEds=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down Expand Up @@ -615,8 +617,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
github.com/puzpuzpuz/xsync/v2 v2.4.1 h1:aGdE1C/HaR/QC6YAFdtZXi60Df8/qBIrs8PKrzkItcM=
github.com/puzpuzpuz/xsync/v2 v2.4.1/go.mod h1:gD2H2krq/w52MfPLE+Uy64TzJDVY7lP2znR9qmR35kU=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down Expand Up @@ -1348,8 +1348,6 @@ k8s.io/apiextensions-apiserver v0.35.0 h1:3xHk2rTOdWXXJM+RDQZJvdx0yEOgC0FgQ1PlJa
k8s.io/apiextensions-apiserver v0.35.0/go.mod h1:E1Ahk9SADaLQ4qtzYFkwUqusXTcaV2uw3l14aqpL2LU=
k8s.io/apimachinery v0.35.0 h1:Z2L3IHvPVv/MJ7xRxHEtk6GoJElaAqDCCU0S6ncYok8=
k8s.io/apimachinery v0.35.0/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns=
k8s.io/apiserver v0.35.0 h1:CUGo5o+7hW9GcAEF3x3usT3fX4f9r8xmgQeCBDaOgX4=
k8s.io/apiserver v0.35.0/go.mod h1:QUy1U4+PrzbJaM3XGu2tQ7U9A4udRRo5cyxkFX0GEds=
k8s.io/client-go v0.35.0 h1:IAW0ifFbfQQwQmga0UdoH0yvdqrbwMdq9vIFEhRpxBE=
k8s.io/client-go v0.35.0/go.mod h1:q2E5AAyqcbeLGPdoRB+Nxe3KYTfPce1Dnu1myQdqz9o=
k8s.io/code-generator v0.35.0 h1:TvrtfKYZTm9oDF2z+veFKSCcgZE3Igv0svY+ehCmjHQ=
Expand Down
7 changes: 2 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ func main() {
osFs := afero.NewOsFs()
pool := file.NewPool(filepath.Join(file.DefaultStorageRoot, "metadata.sq3"), 0) // If less than 1, a reasonable default is used.

// setup watcher
watchDispatcher := file.NewWatchDispatcher()

// cleanup task
client, err := file.NewKubernetesClient()
kubernetesAPI := file.NewKubernetesAPI(cfg, client)
Expand All @@ -104,11 +101,11 @@ func main() {

relevancyEnabled := clusterData.RelevantImageVulnerabilitiesEnabled != nil && *clusterData.RelevantImageVulnerabilitiesEnabled

cleanupHandler := file.NewResourcesCleanupHandler(osFs, file.DefaultStorageRoot, pool, watchDispatcher, cfg.CleanupInterval, cfg.DefaultNamespace, kubernetesAPI, relevancyEnabled)
cleanupHandler := file.NewResourcesCleanupHandler(osFs, file.DefaultStorageRoot, pool, cfg.CleanupInterval, cfg.DefaultNamespace, kubernetesAPI, relevancyEnabled)
go cleanupHandler.RunCleanupTask(ctx)

// start the server
options := server.NewWardleServerOptions(os.Stdout, os.Stderr, osFs, pool, cfg, watchDispatcher, cleanupHandler)
options := server.NewWardleServerOptions(os.Stdout, os.Stderr, osFs, pool, cfg, cleanupHandler)
cmd := server.NewCommandStartWardleServer(ctx, options, false)
logger.L().Info("APIServer starting")
code := cli.Run(cmd)
Expand Down
44 changes: 22 additions & 22 deletions pkg/apis/softwarecomposition/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,36 @@ var (
// Adds the list of known types to the given scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&VulnerabilityManifest{},
&VulnerabilityManifestList{},
&VulnerabilityManifestSummary{},
&VulnerabilityManifestSummaryList{},
&WorkloadConfigurationScan{},
&WorkloadConfigurationScanList{},
&WorkloadConfigurationScanSummary{},
&WorkloadConfigurationScanSummaryList{},
&ConfigurationScanSummary{},
&ConfigurationScanSummaryList{},
&VulnerabilitySummary{},
&VulnerabilitySummaryList{},
&ApplicationProfile{},
&ApplicationProfileList{},
&ContainerProfile{},
&ApplicationProfile{},
&ConfigurationScanSummaryList{},
&ConfigurationScanSummary{},
&ContainerProfileList{},
&NetworkNeighborhood{},
&NetworkNeighborhoodList{},
&OpenVulnerabilityExchangeContainer{},
&OpenVulnerabilityExchangeContainerList{},
&ContainerProfile{},
&GeneratedNetworkPolicyList{},
&GeneratedNetworkPolicy{},
&KnownServerList{},
&KnownServer{},
&SBOMSyft{},
&SBOMSyftList{},
&SBOMSyftFiltered{},
&NetworkNeighborhoodList{},
&NetworkNeighborhood{},
&OpenVulnerabilityExchangeContainerList{},
&OpenVulnerabilityExchangeContainer{},
&SBOMSyftFilteredList{},
&SeccompProfile{},
&SBOMSyftFiltered{},
&SBOMSyftList{},
&SBOMSyft{},
&SeccompProfileList{},
&SeccompProfile{},
&VulnerabilityManifestList{},
&VulnerabilityManifestSummaryList{},
&VulnerabilityManifestSummary{},
&VulnerabilityManifest{},
&VulnerabilitySummaryList{},
&VulnerabilitySummary{},
&WorkloadConfigurationScanList{},
&WorkloadConfigurationScanSummaryList{},
&WorkloadConfigurationScanSummary{},
&WorkloadConfigurationScan{},
)
return nil
}
17 changes: 8 additions & 9 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ func init() {

// ExtraConfig holds custom apiserver config
type ExtraConfig struct {
CleanupHandler *file.ResourcesCleanupHandler
OsFs afero.Fs
Pool *sqlitemigration.Pool
StorageConfig config.Config
WatchDispatcher *file.WatchDispatcher
CleanupHandler *file.ResourcesCleanupHandler
OsFs afero.Fs
Pool *sqlitemigration.Pool
StorageConfig config.Config
}

// Config defines the config for the apiserver
Expand Down Expand Up @@ -140,11 +139,11 @@ func (c completedConfig) New() (*WardleServer, error) {
apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(softwarecomposition.GroupName, Scheme, metav1.ParameterCodec, Codecs)

var (
storageImpl = file.NewStorageImpl(c.ExtraConfig.OsFs, file.DefaultStorageRoot, c.ExtraConfig.Pool, c.ExtraConfig.WatchDispatcher, Scheme)
storageImpl = file.NewStorageImpl(c.ExtraConfig.OsFs, file.DefaultStorageRoot, c.ExtraConfig.Pool, Scheme)

applicationProfileStorageImpl = file.NewApplicationProfileStorage(file.NewStorageImplWithCollector(c.ExtraConfig.OsFs, file.DefaultStorageRoot, c.ExtraConfig.Pool, c.ExtraConfig.WatchDispatcher, Scheme, file.NewApplicationProfileProcessor(c.ExtraConfig.StorageConfig)))
containerProfileStorageImpl = file.NewContainerProfileRESTStorage(file.NewStorageImplWithCollector(c.ExtraConfig.OsFs, file.DefaultStorageRoot, c.ExtraConfig.Pool, c.ExtraConfig.WatchDispatcher, Scheme, file.NewContainerProfileProcessor(c.ExtraConfig.StorageConfig, c.ExtraConfig.CleanupHandler)))
networkNeighborhoodStorageImpl = file.NewNetworkNeighborhoodStorage(file.NewStorageImplWithCollector(c.ExtraConfig.OsFs, file.DefaultStorageRoot, c.ExtraConfig.Pool, c.ExtraConfig.WatchDispatcher, Scheme, file.NewNetworkNeighborhoodProcessor(c.ExtraConfig.StorageConfig)))
applicationProfileStorageImpl = file.NewApplicationProfileStorage(file.NewStorageImplWithCollector(c.ExtraConfig.OsFs, file.DefaultStorageRoot, c.ExtraConfig.Pool, Scheme, file.NewApplicationProfileProcessor(c.ExtraConfig.StorageConfig)))
containerProfileStorageImpl = file.NewContainerProfileRESTStorage(file.NewStorageImplWithCollector(c.ExtraConfig.OsFs, file.DefaultStorageRoot, c.ExtraConfig.Pool, Scheme, file.NewContainerProfileProcessor(c.ExtraConfig.StorageConfig, c.ExtraConfig.CleanupHandler)))
networkNeighborhoodStorageImpl = file.NewNetworkNeighborhoodStorage(file.NewStorageImplWithCollector(c.ExtraConfig.OsFs, file.DefaultStorageRoot, c.ExtraConfig.Pool, Scheme, file.NewNetworkNeighborhoodProcessor(c.ExtraConfig.StorageConfig)))
configScanStorageImpl = file.NewConfigurationScanSummaryStorage(storageImpl)
vulnerabilitySummaryStorage = file.NewVulnerabilitySummaryStorage(storageImpl)
generatedNetworkPolicyStorage = file.NewGeneratedNetworkPolicyStorage(storageImpl, networkNeighborhoodStorageImpl)
Expand Down
29 changes: 13 additions & 16 deletions pkg/cmd/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ type WardleServerOptions struct {

AlternateDNS []string

CleanupHandler *file.ResourcesCleanupHandler
OsFs afero.Fs
Pool *sqlitemigration.Pool
StorageConfig config.Config
WatchDispatcher *file.WatchDispatcher
CleanupHandler *file.ResourcesCleanupHandler
OsFs afero.Fs
Pool *sqlitemigration.Pool
StorageConfig config.Config
}

func WardleVersionToKubeVersion(ver *version.Version) *version.Version {
Expand All @@ -93,7 +92,7 @@ func WardleVersionToKubeVersion(ver *version.Version) *version.Version {
}

// NewWardleServerOptions returns a new WardleServerOptions
func NewWardleServerOptions(out, errOut io.Writer, osFs afero.Fs, pool *sqlitemigration.Pool, cfg config.Config, watchDispatcher *file.WatchDispatcher, cleanupHandler *file.ResourcesCleanupHandler) *WardleServerOptions {
func NewWardleServerOptions(out, errOut io.Writer, osFs afero.Fs, pool *sqlitemigration.Pool, cfg config.Config, cleanupHandler *file.ResourcesCleanupHandler) *WardleServerOptions {
o := &WardleServerOptions{
RecommendedOptions: genericoptions.NewRecommendedOptions(
defaultEtcdPathPrefix,
Expand All @@ -104,11 +103,10 @@ func NewWardleServerOptions(out, errOut io.Writer, osFs afero.Fs, pool *sqlitemi
StdOut: out,
StdErr: errOut,

CleanupHandler: cleanupHandler,
OsFs: osFs,
Pool: pool,
StorageConfig: cfg,
WatchDispatcher: watchDispatcher,
CleanupHandler: cleanupHandler,
OsFs: osFs,
Pool: pool,
StorageConfig: cfg,
}
o.RecommendedOptions.Admission = nil
o.RecommendedOptions.Etcd = nil
Expand Down Expand Up @@ -282,11 +280,10 @@ func (o *WardleServerOptions) Config() (*apiserver.Config, error) {
c := &apiserver.Config{
GenericConfig: serverConfig,
ExtraConfig: apiserver.ExtraConfig{
CleanupHandler: o.CleanupHandler,
OsFs: o.OsFs,
Pool: o.Pool,
StorageConfig: o.StorageConfig,
WatchDispatcher: o.WatchDispatcher,
CleanupHandler: o.CleanupHandler,
OsFs: o.OsFs,
Pool: o.Pool,
StorageConfig: o.StorageConfig,
},
}
return c, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/file/applicationprofile_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func (a ApplicationProfileStorage) Delete(ctx context.Context, key string, out r
return a.realStore.Delete(ctx, key, out, preconditions, validateDeletion, cachedExistingObject, opts)
}

func (a ApplicationProfileStorage) Watch(ctx context.Context, key string, opts storage.ListOptions) (watch.Interface, error) {
return a.realStore.Watch(ctx, key, opts)
func (a ApplicationProfileStorage) Watch(_ context.Context, _ string, _ storage.ListOptions) (watch.Interface, error) {
return nil, nil // watch disabled
}

func (a ApplicationProfileStorage) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error {
Expand Down
10 changes: 2 additions & 8 deletions pkg/registry/file/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type ResourcesCleanupHandler struct {
fetcher ResourcesFetcher
deleteFunc TypeDeleteFunc
resourceToKindHandler map[string][]TypeCleanupHandlerFunc
watchDispatcher *WatchDispatcher
}

func initResourceToKindHandler(relevancyEnabled bool) map[string][]TypeCleanupHandlerFunc {
Expand Down Expand Up @@ -77,7 +76,7 @@ func initResourceToKindHandler(relevancyEnabled bool) map[string][]TypeCleanupHa
return resourceKindToHandler
}

func NewResourcesCleanupHandler(appFs afero.Fs, root string, pool *sqlitemigration.Pool, watchDispatcher *WatchDispatcher, interval time.Duration, defaultNamespace string, fetcher ResourcesFetcher, relevancyEnabled bool) *ResourcesCleanupHandler {
func NewResourcesCleanupHandler(appFs afero.Fs, root string, pool *sqlitemigration.Pool, interval time.Duration, defaultNamespace string, fetcher ResourcesFetcher, relevancyEnabled bool) *ResourcesCleanupHandler {

return &ResourcesCleanupHandler{
appFs: appFs,
Expand All @@ -88,7 +87,6 @@ func NewResourcesCleanupHandler(appFs afero.Fs, root string, pool *sqlitemigrati
fetcher: fetcher,
deleteFunc: deleteFile,
resourceToKindHandler: initResourceToKindHandler(relevancyEnabled),
watchDispatcher: watchDispatcher,
}
}

Expand Down Expand Up @@ -197,11 +195,7 @@ func (h *ResourcesCleanupHandler) cleanupNamespace(ctx context.Context, ns strin
logger.L().Debug("deleting", helpers.String("kind", resourceKind), helpers.String("namespace", metadata.Namespace), helpers.String("name", metadata.Name))
h.deleteFunc(h.appFs, path)

metaOut := h.deleteMetadata(conn, path)
if h.watchDispatcher != nil {
key := path[len(h.root) : len(path)-len(GobExt)]
h.watchDispatcher.Deleted(key, metaOut)
}
_ = h.deleteMetadata(conn, path)
}
return nil
})
Expand Down
13 changes: 7 additions & 6 deletions pkg/registry/file/configurationscansummarystorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
"zombiezen.com/go/sqlite/sqlitemigration"
)


func TestConfigurationScanSummaryStorage_Create(t *testing.T) {
storageImpl := NewStorageImpl(afero.NewMemMapFs(), "", nil, nil, nil)
storageImpl := NewStorageImpl(afero.NewMemMapFs(), "", nil, nil)
configScanSummaryStorage := NewConfigurationScanSummaryStorage(storageImpl)

err := configScanSummaryStorage.Create(context.TODO(), "", nil, nil, 0)
Expand All @@ -29,7 +30,7 @@ func TestConfigurationScanSummaryStorage_Create(t *testing.T) {
}

func TestConfigurationScanSummaryStorage_Delete(t *testing.T) {
storageImpl := NewStorageImpl(afero.NewMemMapFs(), "", nil, nil, nil)
storageImpl := NewStorageImpl(afero.NewMemMapFs(), "", nil, nil)
configScanSummaryStorage := NewConfigurationScanSummaryStorage(storageImpl)

err := configScanSummaryStorage.Delete(context.TODO(), "", nil, nil, nil, nil, storage.DeleteOptions{})
Expand All @@ -40,15 +41,15 @@ func TestConfigurationScanSummaryStorage_Delete(t *testing.T) {
}

func TestConfigurationScanSummaryStorage_Watch(t *testing.T) {
storageImpl := NewStorageImpl(afero.NewMemMapFs(), "", nil, nil, nil)
storageImpl := NewStorageImpl(afero.NewMemMapFs(), "", nil, nil)
configScanSummaryStorage := NewConfigurationScanSummaryStorage(storageImpl)

_, err := configScanSummaryStorage.Watch(context.TODO(), "", storage.ListOptions{})
assert.NoError(t, err)
}

func TestConfigurationScanSummaryStorage_GuaranteedUpdate(t *testing.T) {
storageImpl := NewStorageImpl(afero.NewMemMapFs(), "", nil, nil, nil)
storageImpl := NewStorageImpl(afero.NewMemMapFs(), "", nil, nil)
configScanSummaryStorage := NewConfigurationScanSummaryStorage(storageImpl)

err := configScanSummaryStorage.GuaranteedUpdate(context.TODO(), "", nil, false, nil, nil, nil)
Expand Down Expand Up @@ -102,7 +103,7 @@ func TestConfigurationScanSummaryStorage_Get(t *testing.T) {
}(pool)
sch := scheme.Scheme
require.NoError(t, softwarecomposition.AddToScheme(sch))
realStorage := NewStorageImpl(afero.NewMemMapFs(), "/", pool, nil, sch)
realStorage := NewStorageImpl(afero.NewMemMapFs(), "/", pool, sch)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -177,7 +178,7 @@ func TestConfigurationScanSummaryStorage_GetList(t *testing.T) {
}(pool)
sch := scheme.Scheme
require.NoError(t, softwarecomposition.AddToScheme(sch))
realStorage := NewStorageImpl(afero.NewMemMapFs(), "/", pool, nil, sch)
realStorage := NewStorageImpl(afero.NewMemMapFs(), "/", pool, sch)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
15 changes: 7 additions & 8 deletions pkg/registry/file/containerprofile_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ func TestConsolidateData(t *testing.T) {
MaxContainerProfileSize: 40000,
}
s := &StorageImpl{
appFs: afero.NewMemMapFs(),
pool: pool,
locks: utils.NewMapMutex[string](),
processor: &processor,
root: DefaultStorageRoot,
scheme: sch,
versioner: storage.APIObjectVersioner{},
watchDispatcher: NewWatchDispatcher(),
appFs: afero.NewMemMapFs(),
pool: pool,
locks: utils.NewMapMutex[string](),
processor: &processor,
root: DefaultStorageRoot,
scheme: sch,
versioner: storage.APIObjectVersioner{},
}
processor.SetStorage(NewContainerProfileStorageImpl(s, pool))

Expand Down
Loading
Loading