Skip to content

Commit

Permalink
Return empty mapping for non scaling ops requests (#64)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Aug 29, 2024
1 parent 65fabfd commit 1a8ea42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion api/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ limitations under the License.

package api

import core "k8s.io/api/core/v1"
import (
"errors"

core "k8s.io/api/core/v1"
)

type PodRole string

Expand Down Expand Up @@ -56,6 +60,8 @@ const (
PodRoleRouters PodRole = "routers"
)

var ErrMissingRefObject = errors.New("referenced object not found")

type ReplicaList map[PodRole]int64

type PodInfo struct {
Expand Down
14 changes: 11 additions & 3 deletions ops.kubedb.com/v1alpha1/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package v1alpha1

import (
"errors"
"fmt"
"strings"

"kmodules.xyz/resource-metrics/api"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand Down Expand Up @@ -69,7 +70,14 @@ func extractReferencedObject(opsObj map[string]interface{}, refDbPath ...string)
}
dbObj, found, _ := unstructured.NestedMap(opsObj, refDbPath...)
if !found {
return nil, errors.New("referenced db object not found")
return nil, api.ErrMissingRefObject
}

_, foundApiVersion := dbObj["apiVersion"]
_, foundKind := dbObj["kind"]
_, foundMetadata := dbObj["metadata"]
if !foundApiVersion || !foundKind || !foundMetadata {
return nil, api.ErrMissingRefObject
}

return dbObj, nil
Expand Down Expand Up @@ -106,5 +114,5 @@ func getMapping(opsObj OpsReqObject, opsMapper OpsPathMapper) (map[OpsReqPath]Re
return opsMapper.VolumeExpansionPathMapping(), nil
}

return nil, fmt.Errorf("scaling type `%s` not supported", scalingType)
return nil, nil
}

0 comments on commit 1a8ea42

Please sign in to comment.