-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it usable as a library, namespace can be configured
- Loading branch information
Showing
3 changed files
with
89 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package verify | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type VerifyResult struct { | ||
Success bool | ||
|
||
DeploymentsSuccess bool | ||
CertificateSuccess bool | ||
|
||
DeploymentsResult []DeploymentResult | ||
CertificateError error | ||
} | ||
|
||
type CertificateResult struct { | ||
Success bool | ||
Error error | ||
} | ||
|
||
type Options struct { | ||
CertManagerNamespace string | ||
} | ||
|
||
func Verify(ctx context.Context, config *rest.Config, options *Options) (*VerifyResult, error) { | ||
kubeClient, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to get kubernetes client: %v", err) | ||
} | ||
dynamicClient, err := dynamic.NewForConfig(config) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to get kubernetes client: %v", err) | ||
} | ||
|
||
deployments := DeploymentDefinitionDefault(options.CertManagerNamespace) | ||
deploymentResult := DeploymentsReady(ctx, kubeClient, deployments) | ||
|
||
result := &VerifyResult{ | ||
Success: false, | ||
DeploymentsResult: deploymentResult, | ||
} | ||
|
||
if !allReady(deploymentResult) { | ||
return result, nil | ||
} | ||
result.DeploymentsSuccess = true | ||
err = WaitForTestCertificate(ctx, dynamicClient) | ||
if err != nil { | ||
result.CertificateError = err | ||
} else { | ||
result.CertificateSuccess = true | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func allReady(result []DeploymentResult) bool { | ||
for _, r := range result { | ||
if !r.Ready { | ||
return false | ||
} | ||
} | ||
return true | ||
} |