-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Health Checks Provider to interact with Google Cloud #1763
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 healthchecksl4 | ||
|
||
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 { | ||
// EnsureHealthCheck creates health check (and firewall rule) for l4 service | ||
EnsureHealthCheck(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 healthchecksprovider | ||
|
||
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) 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 | ||
} | ||
|
||
func (hc *HealthChecks) createKey(name string, scope meta.KeyType) (*meta.Key, error) { | ||
return composite.CreateKey(hc.cloud, name, scope) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it's better to name the package l4healthchecks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT?