Skip to content
Merged
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
13 changes: 13 additions & 0 deletions pkg/operator/resource/resourceapply/resource_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/md5"
"fmt"
"io"
"reflect"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -42,10 +43,16 @@ func NewResourceCache() *resourceCache {
var noCache *resourceCache

func getResourceMetadata(obj runtime.Object) (schema.GroupKind, string, string, string, error) {
if obj == nil {
return schema.GroupKind{}, "", "", "", fmt.Errorf("nil object has no metadata")
}
metadata, err := meta.Accessor(obj)
if err != nil {
return schema.GroupKind{}, "", "", "", err
}
if metadata == nil || reflect.ValueOf(metadata).IsNil() {
return schema.GroupKind{}, "", "", "", fmt.Errorf("object has no metadata")
}
resourceHash := hashOfResourceStruct(obj)

// retrieve kind, sometimes this can be done via the accesor, sometimes not (depends on the type)
Expand All @@ -66,10 +73,16 @@ func getResourceMetadata(obj runtime.Object) (schema.GroupKind, string, string,
}

func getResourceVersion(obj runtime.Object) (string, error) {
if obj == nil {
return "", fmt.Errorf("nil object has no resourceVersion")
}
metadata, err := meta.Accessor(obj)
if err != nil {
return "", err
}
if metadata == nil || reflect.ValueOf(metadata).IsNil() {
return "", fmt.Errorf("object has no metadata")
}
rv := metadata.GetResourceVersion()
if len(rv) == 0 {
return "", fmt.Errorf("missing resourceVersion")
Expand Down