This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[validate] Add logic for validation and test cases
This commit adds: 1. Logic for validation of helm, registryV1 and plain bundles. 2. Tests for image source and a mock store implementation for use. Signed-off-by: Varsha Prasad Narsing <[email protected]>
- Loading branch information
1 parent
cfd0cd1
commit 9c1a6fd
Showing
30 changed files
with
2,276 additions
and
45 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
56 changes: 56 additions & 0 deletions
56
internal/v1alpha2/controllers/bundledeployment/bundledeployment_status.go
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,56 @@ | ||
/* | ||
Copyright 2023. | ||
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 bundledeployment | ||
|
||
import ( | ||
"github.com/operator-framework/rukpak/api/v1alpha2" | ||
apimeta "k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// setUnpackStatusFailing sets the unpack status condition to failing. | ||
func setUnpackStatusFailing(conditions *[]metav1.Condition, message string, generation int64) { | ||
apimeta.SetStatusCondition(conditions, metav1.Condition{ | ||
Type: v1alpha2.TypeUnpacked, | ||
Status: metav1.ConditionFalse, | ||
Reason: v1alpha2.ReasonUnpackFailed, | ||
Message: message, | ||
ObservedGeneration: generation, | ||
}) | ||
} | ||
|
||
// setUnpackStatusPending sets the unpack status condition to pending. | ||
func setUnpackStatusPending(conditions *[]metav1.Condition, message string, generation int64) { | ||
apimeta.SetStatusCondition(conditions, metav1.Condition{ | ||
Type: v1alpha2.TypeUnpacked, | ||
Status: metav1.ConditionFalse, | ||
Reason: v1alpha2.ReasonUnpackPending, | ||
Message: message, | ||
ObservedGeneration: generation, | ||
}) | ||
} | ||
|
||
// setUnpackStatusSuccessful sets the unpack status condition to success. | ||
func setUnpackStatusSuccessful(conditions *[]metav1.Condition, message string, generation int64) { | ||
apimeta.SetStatusCondition(conditions, metav1.Condition{ | ||
Type: v1alpha2.TypeUnpacked, | ||
Status: metav1.ConditionTrue, | ||
Reason: v1alpha2.ReasonUnpackSuccessful, | ||
Message: message, | ||
ObservedGeneration: generation, | ||
}) | ||
} |
76 changes: 76 additions & 0 deletions
76
internal/v1alpha2/controllers/bundledeployment/bundledeployment_suite_test.go
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,76 @@ | ||
/* | ||
Copyright 2023. | ||
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 bundledeployment | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/operator-framework/rukpak/api/v1alpha2" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/rest" | ||
"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" | ||
) | ||
|
||
var ( | ||
cfg *rest.Config | ||
cl client.Client | ||
sch *runtime.Scheme | ||
testEnv *envtest.Environment | ||
) | ||
|
||
var _ = BeforeSuite(func() { | ||
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) | ||
|
||
By("bootstrapping test environment") | ||
testEnv = &envtest.Environment{ | ||
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "manifests", "base", "apis", "crds")}, | ||
ErrorIfCRDPathMissing: true, | ||
} | ||
|
||
var err error | ||
// cfg is defined in this file globally. | ||
cfg, err = testEnv.Start() | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(cfg).NotTo(BeNil()) | ||
|
||
sch = runtime.NewScheme() | ||
err = corev1.AddToScheme(sch) | ||
Expect(err).NotTo(HaveOccurred()) | ||
err = v1alpha2.AddToScheme(sch) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
cl, err = client.New(cfg, client.Options{Scheme: sch}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(cl).NotTo(BeNil()) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
err := testEnv.Stop() | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
func TestAPIs(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Controller Suite") | ||
} |
53 changes: 53 additions & 0 deletions
53
internal/v1alpha2/controllers/bundledeployment/bundledeployment_test.go
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,53 @@ | ||
/* | ||
Copyright 2023. | ||
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 bundledeployment | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/types" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
var _ = Describe("Bundledeployment controller test", func() { | ||
var ( | ||
ctx context.Context | ||
reconciler bundleDeploymentReconciler | ||
) | ||
|
||
BeforeEach(func() { | ||
ctx = context.Background() | ||
reconciler = bundleDeploymentReconciler{ | ||
Client: cl, | ||
Scheme: sch, | ||
} | ||
}) | ||
|
||
When("the bundle deployment does not exist", func() { | ||
It("does not return an error", func() { | ||
res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: types.NamespacedName{Name: "non-existent"}}) | ||
Expect(res).To(Equal(ctrl.Result{})) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
When("the bundle deployment exists on cluster", func() { | ||
}) | ||
|
||
}) |
Oops, something went wrong.