• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / sig-storage-local-static-provisioner / 15647678743

14 Jun 2025 02:54AM UTC coverage: 51.195% (-2.4%) from 53.585%
15647678743

push

github

web-flow
Merge pull request #500 from andyzhangx/CVE-2025-4673

test: fix CVE-2025-4673 in trivy action

964 of 1883 relevant lines covered (51.19%)

7.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/cache/cache.go
1
/*
2
Copyright 2017 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package cache
18

19
import (
20
        "sync"
21

22
        "k8s.io/klog/v2"
23

24
        v1 "k8s.io/api/core/v1"
25
)
26

27
// VolumeCache keeps all the PersistentVolumes that have been created by this provisioner.
28
// It is periodically updated by the Populator.
29
// The Deleter and Discoverer use the VolumeCache to check on created PVs
30
type VolumeCache struct {
31
        mutex sync.Mutex
32
        pvs   map[string]*v1.PersistentVolume
33
}
34

35
// NewVolumeCache creates a new PV cache object for storing PVs created by this provisioner.
36
func NewVolumeCache() *VolumeCache {
×
37
        return &VolumeCache{pvs: map[string]*v1.PersistentVolume{}}
×
38
}
×
39

40
// GetPV returns the PV object given the PV name
41
func (cache *VolumeCache) GetPV(pvName string) (*v1.PersistentVolume, bool) {
×
42
        cache.mutex.Lock()
×
43
        defer cache.mutex.Unlock()
×
44

×
45
        pv, exists := cache.pvs[pvName]
×
46
        return pv, exists
×
47
}
×
48

49
// AddPV adds the PV object to the cache
50
func (cache *VolumeCache) AddPV(pv *v1.PersistentVolume) {
×
51
        cache.mutex.Lock()
×
52
        defer cache.mutex.Unlock()
×
53

×
54
        cache.pvs[pv.Name] = pv
×
55
        klog.Infof("Added pv %q to cache", pv.Name)
×
56
}
×
57

58
// UpdatePV updates the PV object in the cache
59
func (cache *VolumeCache) UpdatePV(pv *v1.PersistentVolume) {
×
60
        cache.mutex.Lock()
×
61
        defer cache.mutex.Unlock()
×
62

×
63
        cache.pvs[pv.Name] = pv
×
64
        klog.Infof("Updated pv %q to cache", pv.Name)
×
65
}
×
66

67
// DeletePV deletes the PV object from the cache
68
func (cache *VolumeCache) DeletePV(pvName string) {
×
69
        cache.mutex.Lock()
×
70
        defer cache.mutex.Unlock()
×
71

×
72
        delete(cache.pvs, pvName)
×
73
        klog.Infof("Deleted pv %q from cache", pvName)
×
74
}
×
75

76
// ListPVs returns a list of all the PVs in the cache
77
func (cache *VolumeCache) ListPVs() []*v1.PersistentVolume {
×
78
        cache.mutex.Lock()
×
79
        defer cache.mutex.Unlock()
×
80

×
81
        pvs := []*v1.PersistentVolume{}
×
82
        for _, pv := range cache.pvs {
×
83
                pvs = append(pvs, pv)
×
84
        }
×
85
        return pvs
×
86
}
87

88
// LookupPVsByPath returns a list of all of the PVs in the cache with a given local path
89
// Note: The PVs in the cache have been filtered by the populator so that the cache only
90
// contains volumes created by the local-static-provisioner running on this knode.
91
func (cache *VolumeCache) LookupPVsByPath(filePath string) []string {
×
92
        cache.mutex.Lock()
×
93
        defer cache.mutex.Unlock()
×
94
        var matches = make([]string, 0, 1)
×
95

×
96
        for _, pv := range cache.pvs {
×
97
                lvs := pv.Spec.Local
×
98
                if lvs != nil {
×
99
                        if lvs.Path == filePath {
×
100
                                matches = append(matches, pv.ObjectMeta.Name)
×
101
                        }
×
102
                }
103
        }
104

105
        return matches
×
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc