Skip to content

Commit

Permalink
Rework GetAppRefPath (#57)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Jun 7, 2024
1 parent 7d8f94b commit c20a6e6
Show file tree
Hide file tree
Showing 2,078 changed files with 1,025,330 additions and 24 deletions.
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/elasticsearch_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (m *ElasticsearchOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Re
}
}

func (m *ElasticsearchOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *ElasticsearchOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *ElasticsearchOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/kafka_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (m *kafkaOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Referenced
}
}

func (m *kafkaOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *kafkaOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *kafkaOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
2 changes: 1 addition & 1 deletion ops.kubedb.com/v1alpha1/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type OpsPathMapper interface {
HorizontalPathMapping() map[OpsReqPath]ReferencedObjPath
VerticalPathMapping() map[OpsReqPath]ReferencedObjPath
VolumeExpansionPathMapping() map[OpsReqPath]ReferencedObjPath
GetReferencedDbObjectPath() []string
GetAppRefPath() []string
GroupVersionKind() schema.GroupVersionKind
}

Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/mariadb_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (m *MariaDBOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Referenc
return map[OpsReqPath]ReferencedObjPath{}
}

func (m *MariaDBOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *MariaDBOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *MariaDBOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/memcached_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (m *MemcachedOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Refere
return map[OpsReqPath]ReferencedObjPath{}
}

func (m *MemcachedOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *MemcachedOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *MemcachedOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/mongodb_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func (m *MongoDBOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Referenc
}
}

func (m *MongoDBOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *MongoDBOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *MongoDBOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/mysql_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (m *MySqlOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Referenced
}
}

func (m *MySqlOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *MySqlOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *MySqlOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/pgbouncer_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (m *PgBouncerOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Refere
return map[OpsReqPath]ReferencedObjPath{}
}

func (m *PgBouncerOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *PgBouncerOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *PgBouncerOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/postgres_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (m *PostgresOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Referen
}
}

func (m *PostgresOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *PostgresOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *PostgresOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
2 changes: 1 addition & 1 deletion ops.kubedb.com/v1alpha1/proxysql_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (m *ProxySQLOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Referen
return map[OpsReqPath]ReferencedObjPath{}
}

func (m *ProxySQLOpsRequest) GetReferencedDbObjectPath() []string {
func (m *ProxySQLOpsRequest) GetAppRefPath() []string {
return []string{"spec", "proxyRef", "referencedDB"}
}

Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/redis_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (m *RedisOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Referenced
}
}

func (m *RedisOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *RedisOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *RedisOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/redissentinel_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (m *RedisSentinelOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Re
}
}

func (m *RedisSentinelOpsRequest) GetReferencedDbObjectPath() []string {
return []string{"spec", "databaseRef", "referencedDB"}
func (m *RedisSentinelOpsRequest) GetAppRefPath() []string {
return []string{"spec", "databaseRef"}
}

func (m *RedisSentinelOpsRequest) GroupVersionKind() schema.GroupVersionKind {
Expand Down
4 changes: 2 additions & 2 deletions ops.kubedb.com/v1alpha1/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetScaledObject(opsObj map[string]interface{}) (ScaledObject, error) {
if err != nil {
return nil, err
}
dbObj, err := extractReferencedObject(opsObj, opsPathMapper.GetReferencedDbObjectPath()...)
dbObj, err := extractReferencedObject(opsObj, opsPathMapper.GetAppRefPath()...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -65,7 +65,7 @@ func splitPathToSlice(path string) []string {

func extractReferencedObject(opsObj map[string]interface{}, refDbPath ...string) (map[string]interface{}, error) {
if len(refDbPath) == 0 {
refDbPath = []string{"spec", "databaseRef", "referencedDB"}
return nil, errors.New("refDbPath is empty")
}
dbObj, found, _ := unstructured.NestedMap(opsObj, refDbPath...)
if !found {
Expand Down
56 changes: 56 additions & 0 deletions utils/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module kmodules.xyz/resource-metrics/utils

go 1.22.4

require (
k8s.io/apimachinery v0.30.1
kmodules.xyz/client-go v0.30.2
kmodules.xyz/resource-metrics v0.29.6
sigs.k8s.io/controller-runtime v0.18.4
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/pointer v0.1.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.30.1 // indirect
k8s.io/client-go v0.30.1 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f // indirect
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
kmodules.xyz/offshoot-api v0.29.4 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace kmodules.xyz/resource-metrics => ./..
Loading

0 comments on commit c20a6e6

Please sign in to comment.