Skip to content
Closed
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: 3 additions & 0 deletions .github/workflows/basic-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
run: |
make validate
make validate-ci
- name: "Run unit-tests"
run: |
make unit-test
job-new-installation:
needs: validation
runs-on:
Expand Down
20 changes: 18 additions & 2 deletions cmd/node-disk-manager-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"os"

ctrllh "github.com/harvester/harvester/pkg/generated/controllers/longhorn.io"
lhv1beta2 "github.com/harvester/harvester/pkg/generated/controllers/longhorn.io/v1beta2"
"github.com/harvester/webhook/pkg/config"
"github.com/harvester/webhook/pkg/server"
"github.com/harvester/webhook/pkg/server/admission"
Expand Down Expand Up @@ -32,6 +34,10 @@ type resourceCaches struct {
lvmVGCache ctldiskv1.LVMVolumeGroupCache
storageClassCache ctlstoragev1.StorageClassCache
pvCache ctlcorev1.PersistentVolumeCache
volumeCache lhv1beta2.VolumeCache
nodeCache ctlcorev1.NodeCache
backingImageCache lhv1beta2.BackingImageCache
lhNodeCache lhv1beta2.NodeCache
}

func main() {
Expand Down Expand Up @@ -117,7 +123,8 @@ func runWebhookServer(ctx context.Context, cfg *rest.Config, options *config.Opt
bdMutator,
}

bdValidator := blockdevice.NewBlockdeviceValidator(resourceCaches.bdCache, resourceCaches.storageClassCache, resourceCaches.pvCache)
bdValidator := blockdevice.NewBlockdeviceValidator(resourceCaches.bdCache, resourceCaches.storageClassCache, resourceCaches.pvCache,
resourceCaches.volumeCache, resourceCaches.nodeCache, resourceCaches.backingImageCache, resourceCaches.lhNodeCache)
scValidator := storageclass.NewStorageClassValidator(resourceCaches.lvmVGCache)
var validators = []admission.Validator{
bdValidator,
Expand Down Expand Up @@ -156,12 +163,21 @@ func newCaches(ctx context.Context, cfg *rest.Config, threadiness int) (*resourc
if err != nil {
return nil, err
}
starters = append(starters, disks, storageFactory, coreFactory)
lhFactory, err := ctrllh.NewFactoryFromConfig(cfg)
if err != nil {
return nil, err
}

starters = append(starters, disks, storageFactory, coreFactory, lhFactory)
resourceCaches := &resourceCaches{
bdCache: disks.Harvesterhci().V1beta1().BlockDevice().Cache(),
lvmVGCache: disks.Harvesterhci().V1beta1().LVMVolumeGroup().Cache(),
storageClassCache: storageFactory.Storage().V1().StorageClass().Cache(),
pvCache: coreFactory.Core().V1().PersistentVolume().Cache(),
volumeCache: lhFactory.Longhorn().V1beta2().Volume().Cache(),
nodeCache: coreFactory.Core().V1().Node().Cache(),
backingImageCache: lhFactory.Longhorn().V1beta2().BackingImage().Cache(),
lhNodeCache: lhFactory.Longhorn().V1beta2().Node().Cache(),
}

if err := start.All(ctx, threadiness, starters...); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ rules:
resources: [ "storageclasses" ]
verbs: [ "*" ]
- apiGroups: [ "harvesterhci.io" ]
resources: [ "blockdevices", "lvmvolumegroups", "lvmvolumegroups/status" ]
resources: [ "blockdevices", "lvmvolumegroups", "lvmvolumegroups/status"]
verbs: [ "*" ]
- apiGroups: [ "apiregistration.k8s.io" ]
resources: [ "apiservices" ]
Expand All @@ -68,6 +68,12 @@ rules:
- apiGroups: [ "admissionregistration.k8s.io" ]
resources: [ "validatingwebhookconfigurations", "mutatingwebhookconfigurations" ]
verbs: [ "*" ]
- apiGroups: [ "" ]
resources: [ "nodes" ]
verbs: [ "get", "watch", "list" ]
- apiGroups: ["longhorn.io"]
resources: ["volumes", "nodes", "backingimages"]
verbs: [ "get", "watch", "list" ]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
40 changes: 20 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ replace (
require (
github.com/ehazlett/simplelog v0.0.0-20200226020431-d374894e92a4
github.com/harvester/go-common v0.0.0-20250109132713-e748ce72a7ba
github.com/harvester/harvester v1.5.1
github.com/harvester/harvester v1.6.0
github.com/harvester/webhook v0.1.5
github.com/jaypipes/ghw v0.8.1-0.20210701154532-dd036bd38c40
github.com/kevinburke/ssh_config v1.2.0
Expand All @@ -52,11 +52,11 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.10.0
github.com/urfave/cli/v2 v2.3.0
golang.org/x/crypto v0.36.0
golang.org/x/crypto v0.38.0
k8s.io/api v0.33.1
k8s.io/apimachinery v0.33.1
k8s.io/client-go v12.0.0+incompatible
k8s.io/utils v0.0.0-20241210054802-24370beab758
k8s.io/utils v0.0.0-20250502105355-0f33e8f1c979
)

require (
Expand All @@ -65,15 +65,15 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.8.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
Expand All @@ -97,20 +97,20 @@ require (
github.com/rancher/dynamiclistener v0.6.1 // indirect
github.com/rancher/wrangler v1.1.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v3 v3.0.3 // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.30.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.32.0 // indirect
golang.org/x/text v0.25.0 // indirect
golang.org/x/time v0.11.0 // indirect
golang.org/x/tools v0.33.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand All @@ -123,11 +123,11 @@ require (
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-aggregator v0.33.1 // indirect
k8s.io/kube-openapi v0.32.6 // indirect
kubevirt.io/api v1.4.0 // indirect
kubevirt.io/api v1.5.0 // indirect
kubevirt.io/containerized-data-importer-api v1.61.0 // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading