-
Notifications
You must be signed in to change notification settings - Fork 4
Add SLI prober for Garage #651
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
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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingWebhookConfiguration | ||
| metadata: | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,127 @@ | ||
| package probes | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "net/url" | ||
| "time" | ||
|
|
||
| miniolib "github.com/minio/minio-go/v7" | ||
| ) | ||
|
|
||
| type VSHNGarage struct { | ||
| minioClient *miniolib.Client | ||
| httpClient *http.Client | ||
| adminURL string | ||
| adminToken string | ||
| bucketName string | ||
| Service string | ||
| Name string | ||
| ClaimNamespace string | ||
| InstanceNamespace string | ||
| HighAvailable bool | ||
| Organization string | ||
| ServiceLevel string | ||
| CompositionName string | ||
| } | ||
|
|
||
| func (g VSHNGarage) Close() error { | ||
| return nil | ||
| } | ||
|
|
||
| func (g VSHNGarage) GetInfo() ProbeInfo { | ||
| return ProbeInfo{ | ||
| Service: g.Service, | ||
| Name: g.Name, | ||
| ClaimNamespace: g.ClaimNamespace, | ||
| InstanceNamespace: g.InstanceNamespace, | ||
| HighAvailable: g.HighAvailable, | ||
| Organization: g.Organization, | ||
| ServiceLevel: g.ServiceLevel, | ||
| CompositionName: g.CompositionName, | ||
| } | ||
| } | ||
|
|
||
| func (g VSHNGarage) Probe(ctx context.Context) error { | ||
| if err := g.checkAdminHealth(ctx); err != nil { | ||
| return err | ||
| } | ||
| return g.checkS3Write(ctx) | ||
| } | ||
|
|
||
| func (g VSHNGarage) checkAdminHealth(ctx context.Context) error { | ||
| req, err := http.NewRequestWithContext(ctx, http.MethodGet, g.adminURL+"/v2/GetClusterHealth", nil) | ||
| if err != nil { | ||
| return fmt.Errorf("cannot create admin health request: %w", err) | ||
| } | ||
| req.Header.Set("Authorization", "Bearer "+g.adminToken) | ||
|
|
||
| resp, err := g.httpClient.Do(req) | ||
| if err != nil { | ||
| return fmt.Errorf("admin health check failed: %w", err) | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| if resp.StatusCode != http.StatusOK { | ||
|
TheBigLee marked this conversation as resolved.
|
||
| body, _ := io.ReadAll(resp.Body) | ||
| return fmt.Errorf("admin API returned status %d: %s", resp.StatusCode, body) | ||
| } | ||
|
|
||
| var health struct { | ||
| Status string `json:"status"` | ||
| } | ||
| if err := json.NewDecoder(resp.Body).Decode(&health); err != nil { | ||
| return fmt.Errorf("cannot decode admin health response: %w", err) | ||
| } | ||
| if health.Status != "healthy" { | ||
| return fmt.Errorf("garage cluster health is %q", health.Status) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (g VSHNGarage) checkS3Write(ctx context.Context) error { | ||
| x := bytes.NewBufferString("This file is auto-generated, do not edit, VSHN SLI Exporter purposes") | ||
| _, err := g.minioClient.PutObject(ctx, g.bucketName, "vshn-sli-probe", x, int64(x.Len()), miniolib.PutObjectOptions{ContentType: "application/octet-stream"}) | ||
| return err | ||
| } | ||
|
|
||
| func NewGarage(service, name, claimNamespace, instanceNamespace, organization, sla, compositionName, endpointURL, adminToken, bucketName string, ha bool, opts miniolib.Options) (*VSHNGarage, error) { | ||
| u, err := url.Parse(endpointURL) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("cannot parse garage endpoint %q: %w", endpointURL, err) | ||
| } | ||
|
TheBigLee marked this conversation as resolved.
|
||
| if u.Host == "" { | ||
| return nil, fmt.Errorf("garage endpoint %q has no host (add scheme, e.g. http://)", endpointURL) | ||
| } | ||
| if u.Scheme != "http" && u.Scheme != "https" { | ||
| return nil, fmt.Errorf("garage endpoint %q has unsupported scheme %q (must be http or https)", endpointURL, u.Scheme) | ||
| } | ||
|
|
||
| opts.Secure = u.Scheme == "https" | ||
| minioClient, err := miniolib.New(u.Host, &opts) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| adminURL := fmt.Sprintf("%s://%s:3903", u.Scheme, u.Hostname()) | ||
|
|
||
|
TheBigLee marked this conversation as resolved.
|
||
| return &VSHNGarage{ | ||
| minioClient: minioClient, | ||
| httpClient: &http.Client{Timeout: 5 * time.Second}, | ||
| adminURL: adminURL, | ||
| adminToken: adminToken, | ||
| bucketName: bucketName, | ||
| Service: service, | ||
| Name: name, | ||
| ClaimNamespace: claimNamespace, | ||
| InstanceNamespace: instanceNamespace, | ||
| HighAvailable: ha, | ||
| Organization: organization, | ||
| ServiceLevel: sla, | ||
| CompositionName: compositionName, | ||
| }, nil | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.