func AllowVersion()

in pkg/controller/association/conf.go [129:172]


func AllowVersion(resourceVersion version.Version, associated commonv1.Associated, logger logr.Logger, recorder record.EventRecorder) (bool, error) {
	for _, assoc := range associated.GetAssociations() {
		assocRef := assoc.AssociationRef()
		if !assocRef.IsDefined() {
			// no association specified, move on
			continue
		}
		assocConf, err := assoc.AssociationConf()
		if err != nil {
			return false, err
		}
		if assocConf == nil || assocConf.Version == "" {
			// no conf reported yet, this may be the initial resource creation
			logger.Info("Delaying version deployment since the version of an associated resource is not reported yet",
				"version", resourceVersion, "ref_namespace", assocRef.Namespace, "ref_name", assocRef.NameOrSecretName())
			return false, nil
		}
		if assocConf.Version == UnknownVersion {
			// unknown version (happens with an unmanaged FleetServer < 8.x), move on
			return true, nil
		}
		if assocConf.Serverless {
			return true, nil
		}
		refVer, err := version.Parse(assocConf.Version)
		if err != nil {
			logger.Error(err, "Invalid version found in association configuration", "association_version", assocConf.Version)
			return false, nil
		}

		compatibleVersions := refVer.GTE(resourceVersion) || ((refVer.Major == resourceVersion.Major) && (refVer.Minor == resourceVersion.Minor))
		if !compatibleVersions {
			// the version of the referenced resource (example: Elasticsearch) is lower than
			// the desired version of the reconciled resource (example: Kibana)
			logger.Info("Delaying version deployment since a referenced resource is not upgraded yet",
				"version", resourceVersion, "ref_version", refVer,
				"ref_type", assoc.AssociationType(), "ref_namespace", assocRef.Namespace, "ref_name", assocRef.NameOrSecretName())
			recorder.Event(associated, corev1.EventTypeWarning, events.EventReasonDelayed,
				fmt.Sprintf("Delaying deployment of version %s since the referenced %s is not upgraded yet", resourceVersion, assoc.AssociationType()))
			return false, nil
		}
	}
	return true, nil
}