-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reconcile helm resources with hooks + set a healthy state as a …
…default for CRD without a condition block (#301) * reconcile helm resources with hooks * fix linter * fetch default status for custom resources
- Loading branch information
Showing
8 changed files
with
204 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package common_test | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
deploymentsv1alpha1 "github.com/pluralsh/deployment-operator/api/v1alpha1" | ||
"github.com/pluralsh/deployment-operator/pkg/common" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
var _ = Describe("Health Test", Ordered, func() { | ||
Context("Test health functions", func() { | ||
customResource := &deploymentsv1alpha1.MetricsAggregate{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
}, | ||
} | ||
|
||
It("should get default status from CRD without condition block", func() { | ||
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(customResource) | ||
Expect(err).NotTo(HaveOccurred()) | ||
status, err := common.GetResourceHealth(&unstructured.Unstructured{Object: obj}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(status).To(Not(BeNil())) | ||
Expect(*status).To(Equal(common.HealthStatus{ | ||
Status: common.HealthStatusHealthy, | ||
})) | ||
}) | ||
It("should get healthy status from CRD with condition block", func() { | ||
customResource.Status = deploymentsv1alpha1.MetricsAggregateStatus{ | ||
Conditions: []metav1.Condition{ | ||
{ | ||
Type: "Ready", | ||
Status: "True", | ||
}, | ||
}, | ||
} | ||
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(customResource) | ||
Expect(err).NotTo(HaveOccurred()) | ||
status, err := common.GetResourceHealth(&unstructured.Unstructured{Object: obj}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(status).To(Not(BeNil())) | ||
Expect(*status).To(Equal(common.HealthStatus{ | ||
Status: common.HealthStatusHealthy, | ||
})) | ||
}) | ||
|
||
It("should get healthy status from CRD with condition block", func() { | ||
customResource.Status = deploymentsv1alpha1.MetricsAggregateStatus{ | ||
Conditions: []metav1.Condition{ | ||
{ | ||
Type: "Ready", | ||
Status: "False", | ||
}, | ||
}, | ||
} | ||
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(customResource) | ||
Expect(err).NotTo(HaveOccurred()) | ||
status, err := common.GetResourceHealth(&unstructured.Unstructured{Object: obj}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(status).To(Not(BeNil())) | ||
Expect(*status).To(Equal(common.HealthStatus{ | ||
Status: common.HealthStatusProgressing, | ||
})) | ||
}) | ||
|
||
It("should get HealthStatusProgressing status during deletion", func() { | ||
customResource.DeletionTimestamp = &metav1.Time{ | ||
Time: time.Now(), | ||
} | ||
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(customResource) | ||
Expect(err).NotTo(HaveOccurred()) | ||
status, err := common.GetResourceHealth(&unstructured.Unstructured{Object: obj}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(status).To(Not(BeNil())) | ||
Expect(*status).To(Equal(common.HealthStatus{ | ||
Status: common.HealthStatusProgressing, | ||
Message: "Pending deletion", | ||
})) | ||
}) | ||
|
||
}) | ||
}) |
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,66 @@ | ||
/* | ||
Copyright 2024. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common_test | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
) | ||
|
||
// These tests use Ginkgo (BDD-style Go testing framework). Refer to | ||
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. | ||
var testEnv *envtest.Environment | ||
var kClient client.Client | ||
|
||
func TestCommon(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Common Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) | ||
|
||
By("bootstrapping test environment") | ||
testEnv = &envtest.Environment{ | ||
BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s", | ||
fmt.Sprintf("1.28.3-%s-%s", runtime.GOOS, runtime.GOARCH)), | ||
} | ||
|
||
cfg, err := testEnv.Start() | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(cfg).NotTo(BeNil()) | ||
|
||
kClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(kClient).NotTo(BeNil()) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
By("tearing down the test environment") | ||
err := testEnv.Stop() | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) |
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
16 changes: 16 additions & 0 deletions
16
test/helm/yet-another-cloudwatch-exporter/templates/job.yaml
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,16 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: pi | ||
annotations: | ||
"helm.sh/hook": pre-install | ||
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: pi | ||
image: perl:5.34.0 | ||
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] | ||
restartPolicy: Never | ||
backoffLimit: 4 |