Skip to content

Commit

Permalink
Set loglevel in image pruner cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
dmage committed Sep 17, 2020
1 parent 421635b commit 6385bf6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/resource/prunercronjob.go
Expand Up @@ -17,6 +17,7 @@ import (
imageregistryapiv1 "github.com/openshift/api/imageregistry/v1"
operatorapi "github.com/openshift/api/operator/v1"
imageregistryv1listers "github.com/openshift/client-go/imageregistry/listers/imageregistry/v1"
"github.com/openshift/library-go/pkg/operator/loglevel"

"github.com/openshift/cluster-image-registry-operator/pkg/defaults"
)
Expand Down Expand Up @@ -132,6 +133,7 @@ func (gcj *generatorPrunerCronJob) expected() (runtime.Object, error) {
fmt.Sprintf("--keep-younger-than=%s", gcj.getKeepYoungerThan(cr)),
fmt.Sprintf("--ignore-invalid-refs=%t", cr.Spec.IgnoreInvalidImageReferences),
fmt.Sprintf("--prune-registry=%t", gcj.getPruneRegistry(rcr)),
fmt.Sprintf("--loglevel=%d", gcj.getLogLevel(cr)),
"--confirm=true",
},
VolumeMounts: []kcorev1.VolumeMount{
Expand Down Expand Up @@ -235,6 +237,10 @@ func (gcj *generatorPrunerCronJob) getKeepYoungerThan(cr *imageregistryapiv1.Ima
return defaultKeepYoungerThan
}

func (gcj *generatorPrunerCronJob) getLogLevel(cr *imageregistryapiv1.ImagePruner) int {
return loglevel.LogLevelToVerbosity(cr.Spec.LogLevel)
}

func (gcj *generatorPrunerCronJob) Get() (runtime.Object, error) {
return gcj.lister.Get(gcj.GetName())
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/resource/prunercronjob_test.go
Expand Up @@ -61,3 +61,32 @@ func TestGetKeepYoungerThan(t *testing.T) {
}
}
}

func TestLogLevel(t *testing.T) {
testCases := []struct {
imagePruner *imageregistryv1.ImagePruner
want int
}{
{
imagePruner: &imageregistryv1.ImagePruner{
Spec: imageregistryv1.ImagePrunerSpec{},
},
want: 2,
},
{
imagePruner: &imageregistryv1.ImagePruner{
Spec: imageregistryv1.ImagePrunerSpec{
LogLevel: "Debug",
},
},
want: 4,
},
}
for _, tc := range testCases {
g := generatorPrunerCronJob{}
got := g.getLogLevel(tc.imagePruner)
if got != tc.want {
t.Errorf("got %v, want %v (%#+v)", got, tc.want, tc.imagePruner)
}
}
}

0 comments on commit 6385bf6

Please sign in to comment.