Skip to content

Commit 51d8aa6

Browse files
Fix nil ptr error for rule 1001 (#628)
Co-authored-by: Aleksandar Savchev <[email protected]>
1 parent 6be1985 commit 51d8aa6

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

pkg/provider/garden/ruleset/securityhardenedshoot/rules/1001.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ func (r *Rule1001) Run(ctx context.Context) (rule.RuleResult, error) {
113113
return rule.Result(r, rule.ErroredCheckResult("kubernetes version not found in cloudProfile", target)), nil
114114
}
115115

116-
if checkResult, found := r.checkShootVersion(shoot.Spec.Kubernetes.Version, namespacedCloudProfile.Spec.Kubernetes.Versions, target); found {
117-
return rule.Result(r, checkResult), nil
116+
if namespacedCloudProfile.Spec.Kubernetes != nil {
117+
if checkResult, found := r.checkShootVersion(shoot.Spec.Kubernetes.Version, namespacedCloudProfile.Spec.Kubernetes.Versions, target); found {
118+
return rule.Result(r, checkResult), nil
119+
}
118120
}
119121
if checkResult, found := r.checkShootVersion(shoot.Spec.Kubernetes.Version, namespacedCloudProfile.Status.CloudProfileSpec.Kubernetes.Versions, target); found {
120122
return rule.Result(r, checkResult), nil

pkg/provider/garden/ruleset/securityhardenedshoot/rules/1001_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,30 @@ var _ = Describe("#1001", func() {
282282
),
283283
)
284284

285+
It("should correctly use NamespacedCloudProfile status when Spec.Kubernetes is nil", func() {
286+
nsCloudProfile.Spec.Kubernetes = nil
287+
Expect(fakeClient.Update(ctx, nsCloudProfile)).To(Succeed())
288+
289+
shoot.Spec.CloudProfile = &gardencorev1beta1.CloudProfileReference{
290+
Name: "foo",
291+
Kind: "NamespacedCloudProfile",
292+
}
293+
shoot.Spec.Kubernetes.Version = "2"
294+
Expect(fakeClient.Create(ctx, shoot)).To(Succeed())
295+
296+
r = &rules.Rule1001{
297+
Client: fakeClient,
298+
ShootName: shootName,
299+
ShootNamespace: shootNamespace,
300+
}
301+
302+
res, err := r.Run(ctx)
303+
Expect(err).To(BeNil())
304+
Expect(res).To(Equal(rule.RuleResult{RuleID: ruleID, RuleName: ruleName, Severity: severity, CheckResults: []rule.CheckResult{
305+
{Status: rule.Passed, Message: "Shoot uses a Kubernetes version with an allowed classification.", Target: rule.NewTarget("version", "2", "classification", "supported")},
306+
}}))
307+
})
308+
285309
Describe("#ValidateOptions", func() {
286310
It("should not error when options are correct", func() {
287311
options := rules.Options1001{

0 commit comments

Comments
 (0)