Skip to content

Commit

Permalink
Merge pull request #254 from SovereignCloudStack/tg/fix-issue-231-con…
Browse files Browse the repository at this point in the history
…tinue-if-cluster-stack-string-is-invalid

🐛 Fix issue 231: Continue if cluster stack string is invalid
  • Loading branch information
janiskemper authored Sep 4, 2024
2 parents 3dc37fb + c6b6d3f commit a45cc0d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions internal/controller/clusterstack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,7 @@ func getLatestReleaseFromRemoteRepository(ctx context.Context, clusterStack *cso
var clusterStacks clusterstack.ClusterStacks

for _, release := range releases {
clusterStackObject, matches, err := matchesSpec(release, &clusterStack.Spec)
if err != nil {
return nil, fmt.Errorf("failed to get match release tag %q with spec of ClusterStack: %w", release, err)
}

clusterStackObject, matches := matchesSpec(release, clusterStack)
if matches {
clusterStacks = append(clusterStacks, clusterStackObject)
}
Expand Down Expand Up @@ -626,16 +622,22 @@ func matchesOwnerRef(a *metav1.OwnerReference, clusterStack *csov1alpha1.Cluster
return aGV.Group == clusterStack.GroupVersionKind().Group && a.Kind == clusterStack.Kind && a.Name == clusterStack.Name
}

func matchesSpec(str string, spec *csov1alpha1.ClusterStackSpec) (clusterstack.ClusterStack, bool, error) {
func matchesSpec(str string, clusterStack *csov1alpha1.ClusterStack) (clusterstack.ClusterStack, bool) {
csObject, err := clusterstack.NewFromClusterStackReleaseProperties(str)
if err != nil {
return clusterstack.ClusterStack{}, false, fmt.Errorf("failed to get clusterstack object from string %q: %w", str, err)
record.Warnf(
clusterStack,
"FailedToParseClusterStackRelease",
"failed to get clusterstack object from string %q: %s", str, err.Error(),
)

return clusterstack.ClusterStack{}, false
}

return csObject, csObject.Version.Channel == spec.Channel &&
csObject.KubernetesVersion.StringWithDot() == spec.KubernetesVersion &&
csObject.Name == spec.Name &&
csObject.Provider == spec.Provider, nil
return csObject, csObject.Version.Channel == clusterStack.Spec.Channel &&
csObject.KubernetesVersion.StringWithDot() == clusterStack.Spec.KubernetesVersion &&
csObject.Name == clusterStack.Spec.Name &&
csObject.Provider == clusterStack.Spec.Provider
}

func unstructuredSpecEqual(oldObj, newObj map[string]interface{}) (newSpec map[string]interface{}, isEqual bool, err error) {
Expand Down

0 comments on commit a45cc0d

Please sign in to comment.