Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#3008 from jasonvigil/fix-sqlin…
Browse files Browse the repository at this point in the history
…stance-periodics

fix: Fix SQLInstance authorizednetworks periodic
  • Loading branch information
google-oss-prow[bot] authored Oct 28, 2024
2 parents 13c1f7c + d742a13 commit 6e95793
Show file tree
Hide file tree
Showing 32 changed files with 65 additions and 55 deletions.
29 changes: 26 additions & 3 deletions pkg/controller/direct/sql/sqlinstance_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package sql

import (
"strings"

krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/sql/v1beta1"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct"
api "google.golang.org/api/sqladmin/v1beta4"
Expand Down Expand Up @@ -60,9 +62,30 @@ func ApplySQLInstanceGCPDefaults(in *krm.SQLInstance, out *api.DatabaseInstance,
if in.Spec.Settings.IpConfiguration == nil {
// GCP default IpConfiguration.
out.Settings.IpConfiguration = &api.IpConfiguration{
Ipv4Enabled: true,
ServerCaMode: "GOOGLE_MANAGED_INTERNAL_CA",
SslMode: "ALLOW_UNENCRYPTED_AND_ENCRYPTED",
Ipv4Enabled: true,
SslMode: "ALLOW_UNENCRYPTED_AND_ENCRYPTED",
}
}
if in.Spec.Settings.IpConfiguration != nil {
if in.Spec.Settings.IpConfiguration.Ipv4Enabled == nil {
// GCP default IpConfiguration.Ipv4Enabled is true.
out.Settings.IpConfiguration.Ipv4Enabled = true
}
if in.Spec.Settings.IpConfiguration.SslMode == nil {
if out.Settings.IpConfiguration.RequireSsl {
if strings.HasPrefix(out.DatabaseVersion, "MYSQL") || strings.HasPrefix(out.DatabaseVersion, "POSTGRES") {
// If RequireSsl is true, and db version is MySQL or Postgres,
// GCP default SslMode is TRUSTED_CLIENT_CERTIFICATE_REQUIRED.
out.Settings.IpConfiguration.SslMode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"
} else {
// Otherwise, if RequireSsl is true and db version is SQLSERVER,
// GCP default SslMode is ENCRYPTED_ONLY.
out.Settings.IpConfiguration.SslMode = "ENCRYPTED_ONLY"
}
} else {
// If RequireSsl is false, GCP default IpConfiguration.SslMode is ALLOW_UNENCRYPTED_AND_ENCRYPTED.
out.Settings.IpConfiguration.SslMode = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
}
}
}
if in.Spec.Settings.PricingPlan == nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/controller/direct/sql/sqlinstance_equality.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package sql

import (
"reflect"
"sort"

api "google.golang.org/api/sqladmin/v1beta4"
)
Expand Down Expand Up @@ -477,10 +478,22 @@ func IpConfigurationsMatch(desired *api.IpConfiguration, actual *api.IpConfigura
return true
}

// AclEntriesByName implements sort.Interface for []*api.AclEntry based on the Name field.
type AclEntriesByName []*api.AclEntry

func (a AclEntriesByName) Len() int { return len(a) }
func (a AclEntriesByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a AclEntriesByName) Less(i, j int) bool { return a[i].Name < a[j].Name }

func AclEntryListsMatch(desired []*api.AclEntry, actual []*api.AclEntry) bool {
if len(desired) != len(actual) {
return false
}
// We mustiterate over the AclEntry lists in sorted order,
// so that the comparison is deterministic.
sort.Sort(AclEntriesByName(desired))
sort.Sort(AclEntriesByName(actual))
// Compare the AclEntry lists.
for i := 0; i < len(desired); i++ {
if !AclEntriesMatch(desired[i], actual[i]) {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -406,7 +405,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -590,7 +589,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ User-Agent: kcc/controller-manager
"name": "all",
"value": "0.0.0.0/0"
}
]
],
"ipv4Enabled": true,
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
"locationPreference": {
Expand Down Expand Up @@ -409,7 +411,9 @@ User-Agent: kcc/controller-manager
"name": "my-network",
"value": "1.2.3.0/24"
}
]
],
"ipv4Enabled": true,
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
"locationPreference": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -604,7 +603,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -428,7 +427,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -406,7 +405,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -434,7 +433,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -595,7 +594,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE_PLUS",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -408,7 +407,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -434,7 +433,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,8 @@ User-Agent: kcc/controller-manager
"ipConfiguration": {
"ipv4Enabled": false,
"privateNetwork": "projects/${projectId}/global/networks/computenetwork-${uniqueId}",
"requireSsl": true
"requireSsl": true,
"sslMode": "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"
},
"kind": "sql#settings",
"locationPreference": {
Expand Down Expand Up @@ -1505,7 +1506,8 @@ User-Agent: kcc/controller-manager
"ipConfiguration": {
"ipv4Enabled": false,
"privateNetwork": "projects/${projectId}/global/networks/computenetwork-${uniqueId}",
"requireSsl": true
"requireSsl": true,
"sslMode": "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"
},
"kind": "sql#settings",
"locationPreference": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ User-Agent: kcc/controller-manager
},
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -428,7 +427,6 @@ User-Agent: kcc/controller-manager
},
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -392,7 +391,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -424,7 +423,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -485,7 +484,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -584,7 +583,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -810,7 +809,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -415,7 +414,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down Expand Up @@ -576,7 +575,6 @@ User-Agent: kcc/controller-manager
"edition": "ENTERPRISE",
"ipConfiguration": {
"ipv4Enabled": true,
"serverCaMode": "GOOGLE_MANAGED_INTERNAL_CA",
"sslMode": "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
},
"kind": "sql#settings",
Expand Down
Loading

0 comments on commit 6e95793

Please sign in to comment.