Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join of two thema.#Lineage values results in unexpressed joinSchema values #136

Open
IfSentient opened this issue May 5, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@IfSentient
Copy link
Contributor

In kindsys, we have the base shared value for kinds which includes:

_sharedKind: {
    // trimmed
    lineage: thema.#Lineage
}

When a user goes to write a kind, if they use the syntax:

myKind: {
    name: "MyKind"
    lineage: thema.#Lineage & {
        name: "mykind"
        // etc.
    }
}

The resulting unified CUE looks like:

myKind: {
    // trimmed
    lineage: thema.#Lineage & thema.#Lineage & {
        // trimmed
    }
}

Prior to lineage flattening, this did not impact the underlying CUE value of a lineage. However, now if we impose a joinSchema at the kindsys level (for example, _crdSchema in custom kinds, the lineage.Underlying() CUE value is not the same as the CUE value of myKind.lineage which gets passed to the binding. When printing using cue.Value.Format(), _crdSchema is not expanded, and is left as an internal ref field which has no definition.

Example:

Source CUE:

bar: {
	name: "Bar"
	group: "bar"
	crd: {}
	currentVersion: [0,0]
	lineage: thema.#Lineage & {
		name: "bar"
		schemas: [{
			version: [0,0]
			schema: {
				spec: {
					foo: string
				}
			}
		}]
	}
}

After unifying with kindsys.Custom and binding the resulting bar.lineage value, we get:

lineage: {
	joinSchema: _crdSchema
} & {
	// trimmed lineage internals
	name: S.machineName & {
		"bar"
	}
	schemas: [{
		version: [0, 0]
		schema: {
			spec: {
				foo: string
			}
		}
	}]
}

Since _crdSchema is not expanded or defined, this results in invalid CUE.

If we remove the excess thema.#Lineage from bar so that it looks like:

bar: {
	name: "Bar"
	group: "bar"
	crd: {}
	currentVersion: [0,0]
	lineage: {
		name: "bar"
		schemas: [{
			version: [0,0]
			schema: {
				spec: {
					foo: string
				}
			}
		}]
	}
}

After unifying and binding, the lineage.Underlying().Format() looks like:

lineage: thema.#Lineage & {
	joinSchema: {
		metadata: {
			// trimmed
		}
		spec:            _
		_specIsNonEmpty: spec & struct.MinFields(0)
		status: {
			// trimmed
		}
	}
} & {
	name: strings.ToLower(strings.Replace("Bar", "-", "_", -1)) & {
		"bar"
	}
	schemas: [{
		version: [0, 0]
		schema: {
			spec: {
				foo: string
			}
		}
	}]
}

In this case, the resulting underlying value seems totally different, as not only is _crdSchema expanded in the joinSchema, but the lineage internals are not part of the printed cue.Value.

This seems like it may be caused by changes in BindLineage to avoid re-unifying the lineage def, though I'm not sure if that also explains why the resulting value differs in terms of lineage internals as well (the double-unified one has them, the single-unified one does not).

@IfSentient IfSentient added the bug Something isn't working label May 5, 2023
@sdboyer
Copy link
Contributor

sdboyer commented Jun 12, 2023

This may have been impacted (positively) by #173 - do you still have an environment set up in which you can easily reproduce?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants