in pkg/cloud/api/resource.go [62:120]
func (obj *resource[GA, Alpha, Beta]) Diff(other Resource[GA, Alpha, Beta]) (*DiffResult, error) {
switch {
// Comparisons between the same versions don't need conversions.
//
// cmp(GA, GA)
case obj.Version() == meta.VersionGA && other.Version() == meta.VersionGA:
aObj, _ := obj.ToGA()
bObj, _ := other.ToGA()
return diff(aObj, bObj, obj.x.typeTrait.FieldTraits(meta.VersionGA))
// cmp(Alpha, Alpha)
case obj.Version() == meta.VersionAlpha && other.Version() == meta.VersionAlpha:
aObj, _ := obj.ToAlpha()
bObj, _ := other.ToAlpha()
return diff(aObj, bObj, obj.x.typeTrait.FieldTraits(meta.VersionAlpha))
// cmp(Beta, Beta)
case obj.Version() == meta.VersionBeta && other.Version() == meta.VersionBeta:
aObj, _ := obj.ToBeta()
bObj, _ := other.ToBeta()
return diff(aObj, bObj, obj.x.typeTrait.FieldTraits(meta.VersionBeta))
// GA => Alpha, GA => Beta should be safe and supported with a conversion.
//
// cmp(GA, Alpha), cmp(Alpha, GA): convert to Alpha, then compare.
case obj.Version() == meta.VersionGA && other.Version() == meta.VersionAlpha:
fallthrough
case obj.Version() == meta.VersionAlpha && other.Version() == meta.VersionGA:
aObj, err := obj.ToAlpha()
if err != nil {
return nil, fmt.Errorf("Resource.Diff: %s", err)
}
bObj, err := other.ToAlpha()
if err != nil {
return nil, fmt.Errorf("Resource.Diff: %s", err)
}
return diff(aObj, bObj, obj.x.typeTrait.FieldTraits(meta.VersionAlpha))
// cmp(GA, Beta), cmp(Beta, GA): convert to Beta, then compare.
case obj.Version() == meta.VersionGA && other.Version() == meta.VersionBeta:
fallthrough
case obj.Version() == meta.VersionBeta && other.Version() == meta.VersionGA:
aObj, err := obj.ToBeta()
if err != nil {
return nil, fmt.Errorf("Resource.Diff: %s", err)
}
bObj, err := other.ToBeta()
if err != nil {
return nil, fmt.Errorf("Resource.Diff: %s", err)
}
return diff(aObj, bObj, obj.x.typeTrait.FieldTraits(meta.VersionBeta))
// Comparison between Alpha/Beta is not supported right now. This probably
// can work with some manual conversion logic.
case obj.Version() == meta.VersionAlpha && other.Version() == meta.VersionBeta:
return nil, fmt.Errorf("cross alpha/beta diff not supported")
case obj.Version() == meta.VersionBeta && other.Version() == meta.VersionAlpha:
return nil, fmt.Errorf("cross beta/alpha diff not supported")
}
return nil, fmt.Errorf("invalid versions (got a.Version=%s, b.Version=%s)", obj.Version(), other.Version())
}