2019-07-02 19:30:42 +00:00
|
|
|
/*
|
2022-07-04 16:53:02 +00:00
|
|
|
Copyright 2022 DigitalOcean
|
2019-07-02 19:30:42 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-06-26 18:40:25 +00:00
|
|
|
package basic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/digitalocean/clusterlint/checks"
|
|
|
|
"github.com/digitalocean/clusterlint/kube"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
checks.Register(&unusedPVCheck{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type unusedPVCheck struct{}
|
|
|
|
|
|
|
|
// Name returns a unique name for this check.
|
2019-07-02 20:06:24 +00:00
|
|
|
func (p *unusedPVCheck) Name() string {
|
2019-06-26 18:40:25 +00:00
|
|
|
return "unused-pv"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Groups returns a list of group names this check should be part of.
|
2019-07-02 20:06:24 +00:00
|
|
|
func (p *unusedPVCheck) Groups() []string {
|
2019-06-26 18:40:25 +00:00
|
|
|
return []string{"basic"}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Description returns a detailed human-readable description of what this check
|
|
|
|
// does.
|
2019-07-02 20:06:24 +00:00
|
|
|
func (p *unusedPVCheck) Description() string {
|
2019-06-26 18:40:25 +00:00
|
|
|
return "Check if there are unused persistent volumes in the cluster"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs this check on a set of Kubernetes objects. It can return warnings
|
|
|
|
// (low-priority problems) and errors (high-priority problems) as well as an
|
|
|
|
// error value indicating that the check failed to run.
|
2019-07-02 20:06:24 +00:00
|
|
|
func (p *unusedPVCheck) Run(objects *kube.Objects) ([]checks.Diagnostic, error) {
|
2019-06-26 18:40:25 +00:00
|
|
|
var diagnostics []checks.Diagnostic
|
|
|
|
for _, pv := range objects.PersistentVolumes.Items {
|
|
|
|
if pv.Spec.ClaimRef == nil {
|
|
|
|
d := checks.Diagnostic{
|
|
|
|
Severity: checks.Warning,
|
|
|
|
Message: fmt.Sprintf("Unused Persistent Volume '%s'.", pv.GetName()),
|
2019-06-27 12:07:35 +00:00
|
|
|
Kind: checks.PersistentVolume,
|
2019-06-26 18:40:25 +00:00
|
|
|
Object: &pv.ObjectMeta,
|
|
|
|
Owners: pv.ObjectMeta.GetOwnerReferences(),
|
|
|
|
}
|
|
|
|
diagnostics = append(diagnostics, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return diagnostics, nil
|
|
|
|
}
|