Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Aniruddha Basak <aniruddha.basak@syself.com>
  • Loading branch information
aniruddha2000 committed Oct 6, 2023
1 parent 1a27c92 commit 32455ee
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/controller/clusterstack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ func (r *ClusterStackReconciler) SetupWithManager(ctx context.Context, mgr ctrl.

// ClusterStackReleaseToClusterStack is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation
// for ClusterStacks that might get updated by changes in ClusterStackReleases.
func (_ *ClusterStackReconciler) ClusterStackReleaseToClusterStack(ctx context.Context) handler.MapFunc {
func (*ClusterStackReconciler) ClusterStackReleaseToClusterStack(ctx context.Context) handler.MapFunc {
logger := log.FromContext(ctx)
return func(ctx context.Context, o client.Object) []reconcile.Request {
result := []reconcile.Request{}
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/clusterstackrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (r *ClusterStackReleaseReconciler) Reconcile(ctx context.Context, req recon
return reconcile.Result{}, nil
}

shouldRequeue, err := r.templateAndApply(ctx, releaseAssets, clusterStackRelease, kubeClient)
shouldRequeue, err := r.templateAndApply(ctx, &releaseAssets, clusterStackRelease, kubeClient)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to template and apply: %w", err)
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func (r *ClusterStackReleaseReconciler) reconcileDelete(ctx context.Context, rel
}
}

template, err := r.templateClusterClassHelmChart(releaseAssets, clusterStackReleaseCR.Name, clusterStackReleaseCR.Namespace)
template, err := r.templateClusterClassHelmChart(&releaseAssets, clusterStackReleaseCR.Name, clusterStackReleaseCR.Namespace)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to perform helm template: %w", err)
}
Expand Down Expand Up @@ -272,9 +272,9 @@ func (r *ClusterStackReleaseReconciler) updateProviderClusterStackRelease(ctx co
return ready, nil
}

func (r *ClusterStackReleaseReconciler) templateAndApply(ctx context.Context, releaseAssets release.Release, clusterStackRelease *csov1alpha1.ClusterStackRelease, kubeClient kube.Client) (bool, error) {
func (r *ClusterStackReleaseReconciler) templateAndApply(ctx context.Context, releaseAssets *release.Release, clusterStackRelease *csov1alpha1.ClusterStackRelease, kubeClient kube.Client) (bool, error) {
// template helm chart and apply objects
template, err := r.templateClusterClassHelmChart(releaseAssets, clusterStackRelease.Name, clusterStackRelease.Namespace)
template, err := r.templateClusterClassHelmChart(&releaseAssets, clusterStackRelease.Name, clusterStackRelease.Namespace)
if err != nil {
return false, fmt.Errorf("failed to template clusterClass helm chart: %w", err)
}
Expand All @@ -295,7 +295,7 @@ func (r *ClusterStackReleaseReconciler) templateAndApply(ctx context.Context, re
}

// templateClusterClassHelmChart templates the clusterClass helm chart.
func (_ *ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAssets release.Release, name, namespace string) ([]byte, error) {
func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAssets *release.Release, name, namespace string) ([]byte, error) {
clusterClassChart, err := releaseAssets.ClusterClassChartPath()
if err != nil {
return nil, fmt.Errorf("failed to get clusterClass helm chart path: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func getUsedClusterClasses(ctx context.Context, c client.Client, namespace strin
usedClusterClasses := make([]string, 0, len(clusterList.Items))

// list the names of all ClusterClasses that are referenced in Cluster objects
for _, cluster := range clusterList.Items {
for i := range clusterList.Items {
cluster := clusterList.Items[i]
if cluster.Spec.Topology == nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/clusterstack/clusterstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func New(provider, name, kubernetesVersion, csVersion string) (ClusterStack, err
}

// Validate validates a given ClusterStack.
func (cs ClusterStack) Validate() error {
func (cs *ClusterStack) Validate() error {
if cs.Provider == "" {
return ErrInvalidProvider
}
Expand All @@ -147,7 +147,7 @@ func (cs ClusterStack) Validate() error {
return nil
}

func (cs ClusterStack) String() string {
func (cs *ClusterStack) String() string {
// release tag: myprovider-myclusterstack-1-26-v1
return strings.Join([]string{cs.Provider, cs.Name, cs.KubernetesVersion.String(), cs.Version.String()}, Separator)
}
2 changes: 1 addition & 1 deletion pkg/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewFactory() Factory {

var _ Client = &kube{}

func (_ *factory) NewClient(namespace string, resCfg *rest.Config) Client {
func (*factory) NewClient(namespace string, resCfg *rest.Config) Client {
return &kube{
Namespace: namespace,
RestConfig: resCfg,
Expand Down
18 changes: 11 additions & 7 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func New(version string) (Version, error) {
var err error
channel := ChannelStable

re := regexp.MustCompile(`^v\d+(-\b\w+\b[-]\d+)?$`)
re := regexp.MustCompile(`^v\d+(-\b\w+\b-\d+)?$`)
match := re.FindStringSubmatch(version)

if len(match) == 0 {
Expand Down Expand Up @@ -118,19 +118,23 @@ func (csv Version) Compare(input Version) (int, error) {
if csv.Channel != input.Channel {
return 0, fmt.Errorf("cannot compare versions with different channels %s and %s", csv.Channel, input.Channel)
}
if csv.Major > input.Major {

switch {
case csv.Major > input.Major:
return 1, nil
} else if csv.Major < input.Major {
case csv.Major < input.Major:
return -1, nil
} else if csv.Major == input.Major {
if csv.Patch > input.Patch {
case csv.Major == input.Major:
switch {
case csv.Patch > input.Patch:
return 1, nil
} else if csv.Patch < input.Patch {
case csv.Patch < input.Patch:
return -1, nil
} else if csv.Patch == input.Patch {
case csv.Patch == input.Patch:
return 0, nil
}
}

return 0, nil
}

Expand Down

0 comments on commit 32455ee

Please sign in to comment.