Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Remove occurences of Bundle API in handlers, storage, webhook
Browse files Browse the repository at this point in the history
Signed-off-by: Varsha Prasad Narsing <[email protected]>
  • Loading branch information
varshaprasad96 committed Dec 21, 2023
1 parent 9ccb86e commit be01f5f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 454 deletions.
52 changes: 0 additions & 52 deletions api/v1alpha1/bundle_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
Expand Down Expand Up @@ -49,15 +48,6 @@ const (
PhaseUnpacked = "Unpacked"
)

// BundleSpec defines the desired state of Bundle
type BundleSpec struct {
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
// ProvisionerClassName sets the name of the provisioner that should reconcile this BundleDeployment.
ProvisionerClassName string `json:"provisionerClassName"`
// Source defines the configuration for the underlying Bundle content.
Source BundleSource `json:"source"`
}

type BundleSource struct {
// Type defines the kind of Bundle content being sourced.
Type SourceType `json:"type"`
Expand Down Expand Up @@ -145,46 +135,4 @@ type UploadSource struct{}

type ProvisionerID string

// BundleStatus defines the observed state of Bundle
type BundleStatus struct {
Phase string `json:"phase,omitempty"`
ResolvedSource *BundleSource `json:"resolvedSource,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ContentURL string `json:"contentURL,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name=Type,type=string,JSONPath=`.spec.source.type`
//+kubebuilder:printcolumn:name=Phase,type=string,JSONPath=`.status.phase`
//+kubebuilder:printcolumn:name=Age,type=date,JSONPath=`.metadata.creationTimestamp`
//+kubebuilder:printcolumn:name=Provisioner,type=string,JSONPath=`.spec.provisionerClassName`,priority=1
//+kubebuilder:printcolumn:name=Resolved Source,type=string,JSONPath=`.status.resolvedSource`,priority=1

// Bundle is the Schema for the bundles API
type Bundle struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BundleSpec `json:"spec"`
Status BundleStatus `json:"status,omitempty"`
}

func (b *Bundle) ProvisionerClassName() string {
return b.Spec.ProvisionerClassName
}

//+kubebuilder:object:root=true

// BundleList contains a list of Bundle
type BundleList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Bundle `json:"items"`
}

func init() {
SchemeBuilder.Register(&Bundle{}, &BundleList{})
}
14 changes: 4 additions & 10 deletions api/v1alpha1/bundledeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ type BundleDeploymentSpec struct {
Config runtime.RawExtension `json:"config,omitempty"`
}

// BundleTemplate defines the desired state of a Bundle resource
type BundleTemplate struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the desired behavior of the Bundle.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
Spec BundleSpec `json:"spec"`
}

// BundleDeploymentStatus defines the observed state of BundleDeployment
type BundleDeploymentStatus struct {
Expand All @@ -94,6 +84,10 @@ type BundleDeployment struct {
Status BundleDeploymentStatus `json:"status,omitempty"`
}

func (b *BundleDeployment) ProvisionerClassName() string {
return b.Spec.ProvisionerClassName
}

//+kubebuilder:object:root=true

// BundleDeploymentList contains a list of BundleDeployment
Expand Down
119 changes: 0 additions & 119 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controllers/bundledeployment/bundledeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func SetupWithManager(mgr manager.Manager, systemNsCache cache.Cache, systemName
For(&rukpakv1alpha1.BundleDeployment{}, builder.WithPredicates(
util.BundleDeploymentProvisionerFilter(c.provisionerID)),
).
Watches(source.NewKindWithCache(&corev1.Pod{}, systemNsCache), util.MapOwneeToOwnerProvisionerHandler(context.Background(), mgr.GetClient(), l, c.provisionerID, &rukpakv1alpha1.Bundle{})).
Watches(source.NewKindWithCache(&corev1.Pod{}, systemNsCache), util.MapOwneeToOwnerProvisionerHandler(context.Background(), mgr.GetClient(), l, c.provisionerID, &rukpakv1alpha1.BundleDeployment{})).
Watches(source.NewKindWithCache(&corev1.ConfigMap{}, systemNsCache), util.MapConfigMapToBundleDeploymentHandler(context.Background(), mgr.GetClient(), systemNamespace, c.provisionerID)).
Build(c)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions internal/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
var _ = Describe("WithFallbackLoader", func() {
var (
ctx context.Context
primaryBundle *rukpakv1alpha1.Bundle
fallbackBundle *rukpakv1alpha1.Bundle
primaryBundleDeployment *rukpakv1alpha1.BundleDeployment
fallbackBundleDeployment *rukpakv1alpha1.BundleDeployment
primaryStore *LocalDirectory
fallbackStore *LocalDirectory
primaryFS fs.FS
Expand All @@ -32,12 +32,12 @@ var _ = Describe("WithFallbackLoader", func() {

BeforeEach(func() {
ctx = context.Background()
primaryBundle = &rukpakv1alpha1.Bundle{
primaryBundleDeployment = &rukpakv1alpha1.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: util.GenerateBundleName("primary", rand.String(8)),
},
}
fallbackBundle = &rukpakv1alpha1.Bundle{
fallbackBundleDeployment = &rukpakv1alpha1.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: util.GenerateBundleName("fallback", rand.String(8)),
},
Expand All @@ -49,27 +49,27 @@ var _ = Describe("WithFallbackLoader", func() {

primaryStore = &LocalDirectory{RootDirectory: primaryDir}
primaryFS = generateFS()
Expect(primaryStore.Store(ctx, primaryBundle, primaryFS)).To(Succeed())
Expect(primaryStore.Store(ctx, primaryBundleDeployment, primaryFS)).To(Succeed())

fallbackStore = &LocalDirectory{RootDirectory: fallbackDir}
fallbackFS = generateFS()
Expect(fallbackStore.Store(ctx, fallbackBundle, fallbackFS)).To(Succeed())
Expect(fallbackStore.Store(ctx, fallbackBundleDeployment, fallbackFS)).To(Succeed())

store = WithFallbackLoader(primaryStore, fallbackStore)
})

It("should find primary bundle", func() {
loadedTestFS, err := store.Load(ctx, primaryBundle)
loadedTestFS, err := store.Load(ctx, primaryBundleDeployment)
Expect(err).ToNot(HaveOccurred())
Expect(fsEqual(primaryFS, loadedTestFS)).To(BeTrue())
})
It("should find fallback bundle", func() {
loadedTestFS, err := store.Load(ctx, fallbackBundle)
loadedTestFS, err := store.Load(ctx, fallbackBundleDeployment)
Expect(err).ToNot(HaveOccurred())
Expect(fsEqual(fallbackFS, loadedTestFS)).To(BeTrue())
})
It("should fail to find unknown bundle", func() {
unknownBundle := &rukpakv1alpha1.Bundle{
unknownBundle := &rukpakv1alpha1.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: util.GenerateBundleName("unknown", rand.String(8)),
},
Expand Down
61 changes: 0 additions & 61 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ func ReconcileDesiredBundleDeployment(ctx context.Context, c client.Client, bd *
return b, existingBundleDeployments, err
}

func BundleProvisionerFilter(provisionerClassName string) predicate.Predicate {
return predicate.NewPredicateFuncs(func(obj client.Object) bool {
b := obj.(*rukpakv1alpha1.Bundle)
return b.Spec.ProvisionerClassName == provisionerClassName
})
}

func BundleDeploymentProvisionerFilter(provisionerClassName string) predicate.Predicate {
return predicate.NewPredicateFuncs(func(obj client.Object) bool {
b := obj.(*rukpakv1alpha1.BundleDeployment)
Expand Down Expand Up @@ -171,54 +164,6 @@ func MapOwneeToOwnerProvisionerHandler(ctx context.Context, cl client.Client, lo
})
}

// MapBundleToBundleDeployment is responsible for finding the BundleDeployment resource
// that's managing this Bundle in the cluster. In the case that this Bundle is a standalone
// resource, then no BundleDeployment will be returned as static creation of Bundle
// resources is not a supported workflow right now.
func MapBundleToBundleDeployment(ctx context.Context, c client.Client, b rukpakv1alpha1.Bundle) *rukpakv1alpha1.BundleDeployment {
// check whether this is a standalone bundle that was created outside
// of the normal BundleDeployment controller reconciliation process.
if bundleOwnerType := b.Labels[CoreOwnerKindKey]; bundleOwnerType != rukpakv1alpha1.BundleDeploymentKind {
return nil
}
bundleOwnerName := b.Labels[CoreOwnerNameKey]
if bundleOwnerName == "" {
return nil
}

bundleDeployments := &rukpakv1alpha1.BundleDeploymentList{}
if err := c.List(ctx, bundleDeployments); err != nil {
return nil
}
for _, bd := range bundleDeployments.Items {
bd := bd

if bd.GetName() == bundleOwnerName {
return bd.DeepCopy()
}
}
return nil
}

// MapBundleToBundleDeploymentHandler is responsible for requeuing a BundleDeployment resource
// when a new Bundle event has been encountered. In the case that the Bundle resource is a
// standalone resource, then no BundleDeployment will be returned as static creation of Bundle
// resources is not a supported workflow right now. The provisionerClassName parameter is used
// to filter out BundleDeployments that the caller shouldn't be watching.
func MapBundleToBundleDeploymentHandler(ctx context.Context, cl client.Client, provisionerClassName string) handler.MapFunc {
return func(object client.Object) []reconcile.Request {
b := object.(*rukpakv1alpha1.Bundle)

managingBD := MapBundleToBundleDeployment(ctx, cl, *b)
if managingBD == nil {
return nil
}
if managingBD.Spec.ProvisionerClassName != provisionerClassName {
return nil
}
return []reconcile.Request{{NamespacedName: client.ObjectKeyFromObject(managingBD)}}
}
}
func MapConfigMapToBundleDeployment(ctx context.Context, cl client.Client, cmNamespace string, cm corev1.ConfigMap) []*rukpakv1alpha1.BundleDeployment {
bundleDeploymentList := &rukpakv1alpha1.BundleDeploymentList{}
if err := cl.List(ctx, bundleDeploymentList); err != nil {
Expand Down Expand Up @@ -361,12 +306,6 @@ func newLabelSelector(name, kind string) labels.Selector {
return labels.NewSelector().Add(*kindRequirement, *nameRequirement)
}

// NewBundleLabelSelector is responsible for constructing a label.Selector
// for any underlying resources that are associated with the Bundle parameter.
func NewBundleLabelSelector(bundle *rukpakv1alpha1.Bundle) labels.Selector {
return newLabelSelector(bundle.GetName(), rukpakv1alpha1.BundleKind)
}

// NewBundleDeploymentLabelSelector is responsible for constructing a label.Selector
// for any underlying resources that are associated with the BundleDeployment parameter.
func NewBundleDeploymentLabelSelector(bd *rukpakv1alpha1.BundleDeployment) labels.Selector {
Expand Down
Loading

0 comments on commit be01f5f

Please sign in to comment.