Skip to content

✨ Cleanups #854

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 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions api/v1alpha1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const (
TypeInstalled = "Installed"
TypeResolved = "Resolved"
TypeHasValidBundle = "HasValidBundle"
TypeHealthy = "Healthy"

// TypeDeprecated is a rollup condition that is present when
// any of the deprecated conditions are present.
Expand All @@ -94,20 +93,19 @@ const (
TypeChannelDeprecated = "ChannelDeprecated"
TypeBundleDeprecated = "BundleDeprecated"

ReasonErrorGettingClient = "ErrorGettingClient"
ReasonBundleLoadFailed = "BundleLoadFailed"
ReasonBundleLookupFailed = "BundleLookupFailed"
ReasonErrorGettingClient = "ErrorGettingClient"
ReasonBundleLoadFailed = "BundleLoadFailed"

ReasonInstallationFailed = "InstallationFailed"
ReasonInstallationStatusUnknown = "InstallationStatusUnknown"
ReasonInstallationSucceeded = "InstallationSucceeded"
ReasonInvalidSpec = "InvalidSpec"
ReasonResolutionFailed = "ResolutionFailed"
ReasonResolutionUnknown = "ResolutionUnknown"
ReasonSuccess = "Success"
ReasonDeprecated = "Deprecated"
ReasonErrorGettingReleaseState = "ErrorGettingReleaseState"
ReasonUpgradeFailed = "UpgradeFailed"
ReasonCreateDynamicWatchFailed = "CreateDynamicWatchFailed"

ReasonSuccess = "Success"
ReasonDeprecated = "Deprecated"
ReasonErrorGettingReleaseState = "ErrorGettingReleaseState"
ReasonUpgradeFailed = "UpgradeFailed"
ReasonCreateDynamicWatchFailed = "CreateDynamicWatchFailed"
)

func init() {
Expand All @@ -116,7 +114,6 @@ func init() {
TypeInstalled,
TypeResolved,
TypeHasValidBundle,
TypeHealthy,
TypeDeprecated,
TypePackageDeprecated,
TypeChannelDeprecated,
Expand All @@ -126,11 +123,8 @@ func init() {
conditionsets.ConditionReasons = append(conditionsets.ConditionReasons,
ReasonInstallationSucceeded,
ReasonResolutionFailed,
ReasonResolutionUnknown,
ReasonBundleLookupFailed,
ReasonInstallationFailed,
ReasonInstallationStatusUnknown,
ReasonInvalidSpec,
ReasonSuccess,
ReasonDeprecated,
ReasonErrorGettingReleaseState,
Expand Down
41 changes: 0 additions & 41 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
apimachyaml "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -554,46 +553,6 @@ func (r *ClusterExtensionReconciler) generateBundleDeploymentForUnpack(bundlePat
}
}

func (r *ClusterExtensionReconciler) GenerateExpectedBundleDeployment(o ocv1alpha1.ClusterExtension, bundlePath string, bundleProvisioner string) *unstructured.Unstructured {
// We use unstructured here to avoid problems of serializing default values when sending patches to the apiserver.
// If you use a typed object, any default values from that struct get serialized into the JSON patch, which could
// cause unrelated fields to be patched back to the default value even though that isn't the intention. Using an
// unstructured ensures that the patch contains only what is specified. Using unstructured like this is basically
// identical to "kubectl apply -f"

spec := map[string]interface{}{
"installNamespace": o.Spec.InstallNamespace,
"provisionerClassName": bundleProvisioner,
"source": map[string]interface{}{
// TODO: Don't assume image type
"type": string(rukpakv1alpha2.SourceTypeImage),
"image": map[string]interface{}{
"ref": bundlePath,
},
},
}

bd := &unstructured.Unstructured{Object: map[string]interface{}{
"apiVersion": rukpakv1alpha2.GroupVersion.String(),
"kind": rukpakv1alpha2.BundleDeploymentKind,
"metadata": map[string]interface{}{
"name": o.GetName(),
},
"spec": spec,
}}
bd.SetOwnerReferences([]metav1.OwnerReference{
{
APIVersion: ocv1alpha1.GroupVersion.String(),
Kind: "ClusterExtension",
Name: o.Name,
UID: o.UID,
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
},
})
return bd
}

// SetupWithManager sets up the controller with the Manager.
func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error {
controller, err := ctrl.NewControllerManagedBy(mgr).
Expand Down
37 changes: 0 additions & 37 deletions internal/controllers/clusterextension_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/stretchr/testify/require"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"
featuregatetesting "k8s.io/component-base/featuregate/testing"
Expand Down Expand Up @@ -478,42 +477,6 @@ func verifyConditionsInvariants(t *testing.T, ext *ocv1alpha1.ClusterExtension)
}
}

func TestGeneratedBundleDeployment(t *testing.T) {
test := []struct {
name string
clusterExtension ocv1alpha1.ClusterExtension
bundlePath string
bundleProvisioner string
}{
{
name: "when all the specs are provided.",
clusterExtension: ocv1alpha1.ClusterExtension{
ObjectMeta: metav1.ObjectMeta{
Name: "test-bd",
UID: types.UID("test"),
},
Spec: ocv1alpha1.ClusterExtensionSpec{
InstallNamespace: "test-ns",
},
},
bundlePath: "testpath",
bundleProvisioner: "foo",
},
}

for _, tt := range test {
fakeReconciler := &controllers.ClusterExtensionReconciler{}
objUnstructured := fakeReconciler.GenerateExpectedBundleDeployment(tt.clusterExtension, tt.bundlePath, tt.bundleProvisioner)
resultBundleDeployment := &rukpakv1alpha2.BundleDeployment{}
require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(objUnstructured.Object, resultBundleDeployment))
// Verify the fields that have are being taken from cluster extension.
require.Equal(t, tt.clusterExtension.GetName(), resultBundleDeployment.GetName())
require.Equal(t, tt.bundlePath, resultBundleDeployment.Spec.Source.Image.Ref)
require.Equal(t, tt.bundleProvisioner, resultBundleDeployment.Spec.ProvisionerClassName)
require.Equal(t, tt.clusterExtension.Spec.InstallNamespace, resultBundleDeployment.Spec.InstallNamespace)
}
}

func TestClusterExtensionUpgrade(t *testing.T) {
cl, reconciler := newClientAndReconciler(t)
ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cluster_extension_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestClusterExtensionInstallRegistry(t *testing.T) {
t.Log("By eventually reporting a successful resolution and bundle path")
require.EventuallyWithT(t, func(ct *assert.CollectT) {
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
assert.Len(ct, clusterExtension.Status.Conditions, 9)
assert.Len(ct, clusterExtension.Status.Conditions, 8)
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeResolved)
if !assert.NotNil(ct, cond) {
return
Expand Down
Loading