Skip to content

Commit

Permalink
🐛 fix gcp subnetwork navigation from gke resources (#4251)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Jun 18, 2024
1 parent dcdbaa0 commit a87d381
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
52 changes: 27 additions & 25 deletions providers/gcp/resources/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,34 @@ func initGcpProjectComputeService(runtime *plugin.Runtime, args map[string]*llx.
return args, nil, nil
}

type mqlGcpProjectComputeServiceInternal struct {
serviceEnabled bool
}

func (g *mqlGcpProject) compute() (*mqlGcpProjectComputeService, error) {
if g.Id.Error != nil {
return nil, g.Id.Error
}
projectId := g.Id.Data

res, err := CreateResource(g.MqlRuntime, "gcp.project.computeService", map[string]*llx.RawData{
res, err := NewResource(g.MqlRuntime, "gcp.project.computeService", map[string]*llx.RawData{
"projectId": llx.StringData(projectId),
})
if err != nil {
return nil, err
}
computeService := res.(*mqlGcpProjectComputeService)
return computeService, nil
}

serviceEnabled, err := g.isServiceEnabled(service_compute)
func (g *mqlGcpProjectComputeService) enabled() (bool, error) {
gcpProjectRes, err := NewResource(g.MqlRuntime, "gcp.project", map[string]*llx.RawData{"id": llx.StringData(g.ProjectId.Data)})
if err != nil {
return nil, err
return false, err
}
gcpProject := gcpProjectRes.(*mqlGcpProject)

computeService := res.(*mqlGcpProjectComputeService)
computeService.serviceEnabled = serviceEnabled

return computeService, nil
serviceEnabled, err := gcpProject.isServiceEnabled(service_compute)
if err != nil {
return false, err
}
return serviceEnabled, nil
}

func (g *mqlGcpProjectComputeService) id() (string, error) {
Expand Down Expand Up @@ -101,7 +103,7 @@ func initGcpProjectComputeServiceRegion(runtime *plugin.Runtime, args map[string

func (g *mqlGcpProjectComputeService) regions() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -155,7 +157,7 @@ func (g *mqlGcpProjectComputeServiceZone) region() (interface{}, error) {

func (g *mqlGcpProjectComputeService) zones() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -243,7 +245,7 @@ func newMqlMachineType(runtime *plugin.Runtime, entry *compute.MachineType, proj

func (g *mqlGcpProjectComputeService) machineTypes() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -645,7 +647,7 @@ func newMqlComputeServiceInstance(projectId string, zone *mqlGcpProjectComputeSe

func (g *mqlGcpProjectComputeService) instances() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -735,7 +737,7 @@ func (g *mqlGcpProjectComputeServiceDisk) zone() (interface{}, error) {

func (g *mqlGcpProjectComputeService) disks() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -904,7 +906,7 @@ func initGcpProjectComputeServiceFirewall(runtime *plugin.Runtime, args map[stri

func (g *mqlGcpProjectComputeService) firewalls() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -1000,7 +1002,7 @@ func (g *mqlGcpProjectComputeServiceSnapshot) sourceDisk() (interface{}, error)

func (g *mqlGcpProjectComputeService) snapshots() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -1119,7 +1121,7 @@ func (g *mqlGcpProjectComputeServiceImage) sourceDisk() (interface{}, error) {

func (g *mqlGcpProjectComputeService) images() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -1259,7 +1261,7 @@ func initGcpProjectComputeServiceNetwork(runtime *plugin.Runtime, args map[strin

func (g *mqlGcpProjectComputeService) networks() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -1355,7 +1357,7 @@ func initGcpProjectComputeServiceSubnetwork(runtime *plugin.Runtime, args map[st
}
}

obj, err := CreateResource(runtime, "gcp.project.computeService", map[string]*llx.RawData{
obj, err := NewResource(runtime, "gcp.project.computeService", map[string]*llx.RawData{
"projectId": llx.StringData(args["projectId"].Value.(string)),
})
if err != nil {
Expand Down Expand Up @@ -1516,7 +1518,7 @@ func newMqlSubnetwork(projectId string, runtime *plugin.Runtime, subnetwork *com

func (g *mqlGcpProjectComputeService) subnetworks() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -1609,7 +1611,7 @@ func newMqlRouter(projectId string, region *mqlGcpProjectComputeServiceRegion, r

func (g *mqlGcpProjectComputeService) routers() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -1676,7 +1678,7 @@ func (g *mqlGcpProjectComputeService) routers() ([]interface{}, error) {

func (g *mqlGcpProjectComputeService) backendServices() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down Expand Up @@ -1956,7 +1958,7 @@ func networkMode(n *compute.Network) string {

func (g *mqlGcpProjectComputeService) addresses() ([]interface{}, error) {
// when the service is not enabled, we return nil
if !g.serviceEnabled {
if !g.GetEnabled().Data {
return nil, nil
}

Expand Down
2 changes: 2 additions & 0 deletions providers/gcp/resources/gcp.lr
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ private gcp.resourcemanager.binding {
private gcp.project.computeService {
// Project ID
projectId string
// Whether the service is enabled
enabled() bool
// Google Compute Engine instances in a project
instances() []gcp.project.computeService.instance
// Google Compute Engine snapshots in a project
Expand Down
16 changes: 15 additions & 1 deletion providers/gcp/resources/gcp.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions providers/gcp/resources/gcp.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ resources:
addresses: {}
backendServices: {}
disks: {}
enabled: {}
firewalls: {}
forwardingRules: {}
images: {}
Expand Down
5 changes: 3 additions & 2 deletions providers/gcp/resources/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,11 @@ func (g *mqlGcpProjectGkeServiceClusterNetworkConfig) subnetwork() (*mqlGcpProje

// Format is projects/project-1/regions/us-central1/subnetworks/subnet-1
params := strings.Split(subnetPath, "/")
res, err := CreateResource(g.MqlRuntime, "gcp.project.computeService.subnetwork", map[string]*llx.RawData{
regionUrl := strings.SplitN(subnetPath, "/subnetworks", 2)
res, err := NewResource(g.MqlRuntime, "gcp.project.computeService.subnetwork", map[string]*llx.RawData{
"name": llx.StringData(params[len(params)-1]),
"projectId": llx.StringData(params[1]),
"region": llx.StringData(params[3]),
"regionUrl": llx.StringData(regionUrl[0]),
})
if err != nil {
return nil, err
Expand Down

0 comments on commit a87d381

Please sign in to comment.