-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Health Checks Provider to interact with Google Cloud
This separates business logic and handling health checks resources
- Loading branch information
Showing
34 changed files
with
1,909 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package healthchecks_l4 | ||
|
||
import ( | ||
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/ingress-gce/pkg/composite" | ||
"k8s.io/ingress-gce/pkg/utils" | ||
"k8s.io/ingress-gce/pkg/utils/namer" | ||
) | ||
|
||
// L4HealthChecks defines methods for creating and deleting health checks (and their firewall rules) for l4 services | ||
type L4HealthChecks interface { | ||
// EnsureL4HealthCheck creates health check (and firewall rule) for l4 service | ||
EnsureL4HealthCheck(svc *v1.Service, namer namer.L4ResourcesNamer, sharedHC bool, scope meta.KeyType, l4Type utils.L4LBType, nodeNames []string) *EnsureL4HealthCheckResult | ||
// DeleteHealthCheck deletes health check (and firewall rule) for l4 service | ||
DeleteHealthCheck(svc *v1.Service, namer namer.L4ResourcesNamer, sharedHC bool, scope meta.KeyType, l4Type utils.L4LBType) (string, error) | ||
} | ||
|
||
type EnsureL4HealthCheckResult struct { | ||
HCName string | ||
HCLink string | ||
HCFirewallRuleName string | ||
GceResourceInError string | ||
Err error | ||
} | ||
|
||
type HealthChecksProvider interface { | ||
Get(name string, scope meta.KeyType) (*composite.HealthCheck, error) | ||
Create(healthCheck *composite.HealthCheck) error | ||
Update(name string, scope meta.KeyType, updatedHealthCheck *composite.HealthCheck) error | ||
Delete(name string, scope meta.KeyType) error | ||
SelfLink(name string, scope meta.KeyType) (string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package healthchecks_l4 | ||
|
||
import ( | ||
"fmt" | ||
|
||
cloudprovider "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" | ||
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta" | ||
"k8s.io/ingress-gce/pkg/composite" | ||
"k8s.io/ingress-gce/pkg/utils" | ||
"k8s.io/legacy-cloud-providers/gce" | ||
) | ||
|
||
type HealthChecks struct { | ||
cloud *gce.Cloud | ||
version meta.Version | ||
} | ||
|
||
func NewHealthChecks(cloud *gce.Cloud, version meta.Version) *HealthChecks { | ||
return &HealthChecks{ | ||
cloud: cloud, | ||
version: version, | ||
} | ||
} | ||
|
||
func (hc *HealthChecks) createKey(name string, scope meta.KeyType) (*meta.Key, error) { | ||
return composite.CreateKey(hc.cloud, name, scope) | ||
} | ||
|
||
func (hc *HealthChecks) Get(name string, scope meta.KeyType) (*composite.HealthCheck, error) { | ||
key, err := hc.createKey(name, scope) | ||
if err != nil { | ||
return nil, fmt.Errorf("hc.createKey(%s, %s) returned error %w, want nil", name, scope, err) | ||
} | ||
healthCheck, err := composite.GetHealthCheck(hc.cloud, key, hc.version) | ||
if err != nil { | ||
if utils.IsNotFoundError(err) { | ||
return nil, nil | ||
} | ||
return nil, fmt.Errorf("composite.GetHealthCheck(_, %v, %v) returned error %w, want nil", key, meta.VersionGA, err) | ||
} | ||
return healthCheck, nil | ||
} | ||
|
||
func (hc *HealthChecks) Create(healthCheck *composite.HealthCheck) error { | ||
key, err := hc.createKey(healthCheck.Name, healthCheck.Scope) | ||
if err != nil { | ||
return fmt.Errorf("hc.createKey(%s, %s) returned error: %w, want nil", healthCheck.Name, healthCheck.Scope, err) | ||
} | ||
|
||
err = composite.CreateHealthCheck(hc.cloud, key, healthCheck) | ||
if err != nil { | ||
return fmt.Errorf("composite.CreateHealthCheck(_, %s, %v) returned error %w, want nil", key, healthCheck, err) | ||
} | ||
return nil | ||
} | ||
|
||
func (hc *HealthChecks) Update(name string, scope meta.KeyType, updatedHealthCheck *composite.HealthCheck) error { | ||
key, err := hc.createKey(name, scope) | ||
if err != nil { | ||
return fmt.Errorf("hc.createKey(%s, %s) returned error: %w, want nil", name, scope, err) | ||
} | ||
|
||
err = composite.UpdateHealthCheck(hc.cloud, key, updatedHealthCheck) | ||
if err != nil { | ||
return fmt.Errorf("composite.UpdateHealthCheck(_, %s, %v) returned error %w, want nil", key, updatedHealthCheck, err) | ||
} | ||
return nil | ||
} | ||
|
||
func (hc *HealthChecks) Delete(name string, scope meta.KeyType) error { | ||
key, err := hc.createKey(name, scope) | ||
if err != nil { | ||
return fmt.Errorf("hc.createKey(%s, %s) returned error %w, want nil", name, scope, err) | ||
} | ||
|
||
return utils.IgnoreHTTPNotFound(composite.DeleteHealthCheck(hc.cloud, key, hc.version)) | ||
} | ||
|
||
func (hc *HealthChecks) SelfLink(name string, scope meta.KeyType) (string, error) { | ||
key, err := hc.createKey(name, scope) | ||
if err != nil { | ||
return "", fmt.Errorf("hc.createKey(%s, %s) returned error %w, want nil", name, scope, err) | ||
} | ||
|
||
return cloudprovider.SelfLink(meta.VersionGA, hc.cloud.ProjectID(), "healthChecks", key), nil | ||
} |
Oops, something went wrong.