Skip to content

Commit

Permalink
sync: update external libs (#840)
Browse files Browse the repository at this point in the history
Co-authored-by: kononovn <[email protected]>
  • Loading branch information
github-actions[bot] and kononovn authored Dec 23, 2024
1 parent f510767 commit 6085a8f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/schemes/assisted/api/common/zz_generated.deepcopy.go

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

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

4 changes: 2 additions & 2 deletions pkg/schemes/assisted/api/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
RenderedTemplates ClusterInstanceConditionType = "RenderedTemplates"
RenderedTemplatesValidated ClusterInstanceConditionType = "RenderedTemplatesValidated"
RenderedTemplatesApplied ClusterInstanceConditionType = "RenderedTemplatesApplied"
RenderedTemplatesDeleted ClusterInstanceConditionType = "RenderedTemplatesDeleted"
ClusterProvisioned ClusterInstanceConditionType = "Provisioned"
)

Expand Down
13 changes: 8 additions & 5 deletions pkg/schemes/siteconfig/v1alpha1/clusterinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,14 @@ type ClusterInstanceSpec struct {
}

const (
ManifestRenderedSuccess = "rendered"
ManifestRenderedFailure = "failed"
ManifestRenderedValidated = "validated"
ManifestSuppressed = "suppressed"
ManifestPruneFailure = "pruning-attempt-failed"
ManifestRenderedSuccess = "rendered"
ManifestRenderedFailure = "failed"
ManifestRenderedValidated = "validated"
ManifestSuppressed = "suppressed"
ManifestDeleted = "deleted"
ManifestDeletionInProgress = "deletion-in-progress"
ManifestDeletionFailure = "deletion-failed"
ManifestDeletionTimedOut = "deletion-attempt-timed-out"
)

// ManifestReference contains enough information to let you locate the
Expand Down
60 changes: 60 additions & 0 deletions pkg/schemes/siteconfig/v1alpha1/clusterinstance_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ limitations under the License.

package v1alpha1

import (
"fmt"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ExtraAnnotationSearch Looks up a specific manifest Annotation for this cluster
func (c *ClusterInstanceSpec) ExtraAnnotationSearch(kind string) (map[string]string, bool) {
annotations, ok := c.ExtraAnnotations[kind]
Expand Down Expand Up @@ -45,3 +52,56 @@ func (node *NodeSpec) ExtraLabelSearch(kind string, cluster *ClusterInstanceSpec
}
return cluster.ExtraLabelSearch(kind)
}

// MatchesIdentity checks if two ManifestReference objects are equal based on identifying fields.
// These fields are APIGroup, Kind, Name, and Namespace.
func (m *ManifestReference) MatchesIdentity(other *ManifestReference) bool {
if m == nil || other == nil {
return false
}

// Safely compare APIGroup pointers
APIGroupMatches := m.APIGroup == nil && other.APIGroup == nil ||
m.APIGroup != nil && other.APIGroup != nil && *m.APIGroup == *other.APIGroup

// Compare identifying fields
return APIGroupMatches &&
m.Kind == other.Kind &&
m.Name == other.Name &&
m.Namespace == other.Namespace
}

func (m *ManifestReference) UpdateStatus(status, message string) {
if m.Status != status || m.Message != message {
m.Status = status
m.Message = message
m.LastAppliedTime = metav1.Now()
}
}

// String generates a Kubernetes style resource path string from the ManifestReference object
func (m *ManifestReference) String() string {
apiGroup := ""
if m.APIGroup != nil && *m.APIGroup != "" {
apiGroup = fmt.Sprintf(".%s", *m.APIGroup)
}

// Handle Namespace if present
if m.Namespace != "" {
return fmt.Sprintf("%s%s/namespaces/%s/%s", strings.ToLower(m.Kind), apiGroup, m.Namespace, m.Name)
}

// Return without Namespace if it is empty
return fmt.Sprintf("%s%s/%s", strings.ToLower(m.Kind), apiGroup, m.Name)
}

// IndexOfManifestByIdentity searches for a ManifestReference in the given list based on identity fields
// and returns its index. It returns -1 and a not found error if the target is not found.
func IndexOfManifestByIdentity(target *ManifestReference, manifestRefs []ManifestReference) (int, error) {
for i, ref := range manifestRefs {
if ref.MatchesIdentity(target) {
return i, nil
}
}
return -1, fmt.Errorf("ManifestReference (%s) not found", target.String())
}

0 comments on commit 6085a8f

Please sign in to comment.