fix: prevent nil pointer dereference in installCRDs when res is empty

When KubeClient.Build() returns an empty resource slice and the CRD
already exists, accessing res[0].Name causes a panic. Add a length
check before accessing res[0].

Fixes #31552

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
pull/32179/head
Arunesh Dwivedi 4 months ago
parent 699cbb1f26
commit 9cbf94fb60

@ -172,6 +172,10 @@ func (i *Install) installCRDs(crds []chart.CRD) error {
if _, err := i.cfg.KubeClient.Create(res); err != nil {
// If the error is CRD already exists, continue.
if apierrors.IsAlreadyExists(err) {
if len(res) == 0 {
i.cfg.Log("CRD %s is already present. Skipping.", obj.Name)
continue
}
crdName := res[0].Name
i.cfg.Log("CRD %s is already present. Skipping.", crdName)
continue

Loading…
Cancel
Save