@@ -1767,7 +1767,7 @@ func TestGraphBuilder_CELTypeChecking(t *testing.T) {
17671767 wantErr : false ,
17681768 },
17691769 {
1770- name : "valid schema. status field reference " ,
1770+ name : "resource references instance status field (string) " ,
17711771 resourceGraphDefinitionOpts : []generator.ResourceGraphDefinitionOption {
17721772 generator .WithSchema (
17731773 "Application" , "v1alpha1" ,
@@ -1802,6 +1802,127 @@ func TestGraphBuilder_CELTypeChecking(t *testing.T) {
18021802 },
18031803 wantErr : false ,
18041804 },
1805+ {
1806+ name : "resource references instance status field (nested object)" ,
1807+ resourceGraphDefinitionOpts : []generator.ResourceGraphDefinitionOption {
1808+ generator .WithSchema (
1809+ "NetworkApp" , "v1alpha1" ,
1810+ map [string ]interface {}{
1811+ "vpcName" : "string" ,
1812+ },
1813+ map [string ]interface {}{
1814+ "vpcState" : "${vpc.status.state}" ,
1815+ },
1816+ ),
1817+ generator .WithResource ("vpc" , map [string ]interface {}{
1818+ "apiVersion" : "ec2.services.k8s.aws/v1alpha1" ,
1819+ "kind" : "VPC" ,
1820+ "metadata" : map [string ]interface {}{
1821+ "name" : "${schema.spec.vpcName}" ,
1822+ },
1823+ "spec" : map [string ]interface {}{
1824+ "cidrBlocks" : []interface {}{"10.0.0.0/16" },
1825+ },
1826+ }, nil , nil ),
1827+ generator .WithResource ("securitygroup" , map [string ]interface {}{
1828+ "apiVersion" : "ec2.services.k8s.aws/v1alpha1" ,
1829+ "kind" : "SecurityGroup" ,
1830+ "metadata" : map [string ]interface {}{
1831+ "name" : "${schema.spec.vpcName}-sg" ,
1832+ },
1833+ "spec" : map [string ]interface {}{
1834+ "description" : "VPC state is: ${schema.status.vpcState}" ,
1835+ },
1836+ }, nil , nil ),
1837+ },
1838+ wantErr : false ,
1839+ },
1840+ {
1841+ name : "multiple resources reference same instance status field" ,
1842+ resourceGraphDefinitionOpts : []generator.ResourceGraphDefinitionOption {
1843+ generator .WithSchema (
1844+ "Application" , "v1alpha1" ,
1845+ map [string ]interface {}{
1846+ "region" : "string" ,
1847+ },
1848+ map [string ]interface {}{
1849+ "primaryVPCID" : "${vpc.status.vpcID}" ,
1850+ },
1851+ ),
1852+ generator .WithResource ("vpc" , map [string ]interface {}{
1853+ "apiVersion" : "ec2.services.k8s.aws/v1alpha1" ,
1854+ "kind" : "VPC" ,
1855+ "metadata" : map [string ]interface {}{
1856+ "name" : "primary-vpc" ,
1857+ },
1858+ "spec" : map [string ]interface {}{
1859+ "cidrBlocks" : []interface {}{"10.0.0.0/16" },
1860+ },
1861+ }, nil , nil ),
1862+ generator .WithResource ("subnet1" , map [string ]interface {}{
1863+ "apiVersion" : "ec2.services.k8s.aws/v1alpha1" ,
1864+ "kind" : "Subnet" ,
1865+ "metadata" : map [string ]interface {}{
1866+ "name" : "subnet-1" ,
1867+ },
1868+ "spec" : map [string ]interface {}{
1869+ "cidrBlock" : "10.0.1.0/24" ,
1870+ "vpcID" : "${schema.status.primaryVPCID}" ,
1871+ },
1872+ }, nil , nil ),
1873+ generator .WithResource ("subnet2" , map [string ]interface {}{
1874+ "apiVersion" : "ec2.services.k8s.aws/v1alpha1" ,
1875+ "kind" : "Subnet" ,
1876+ "metadata" : map [string ]interface {}{
1877+ "name" : "subnet-2" ,
1878+ },
1879+ "spec" : map [string ]interface {}{
1880+ "cidrBlock" : "10.0.2.0/24" ,
1881+ "vpcID" : "${schema.status.primaryVPCID}" ,
1882+ },
1883+ }, nil , nil ),
1884+ },
1885+ wantErr : false ,
1886+ },
1887+ {
1888+ name : "resource references instance status field (boolean computed)" ,
1889+ resourceGraphDefinitionOpts : []generator.ResourceGraphDefinitionOption {
1890+ generator .WithSchema (
1891+ "Application" , "v1alpha1" ,
1892+ map [string ]interface {}{
1893+ "region" : "string" ,
1894+ },
1895+ map [string ]interface {}{
1896+ "vpcReady" : "${vpc.status.state == 'available'}" ,
1897+ },
1898+ ),
1899+ generator .WithResource ("vpc" , map [string ]interface {}{
1900+ "apiVersion" : "ec2.services.k8s.aws/v1alpha1" ,
1901+ "kind" : "VPC" ,
1902+ "metadata" : map [string ]interface {}{
1903+ "name" : "app-vpc" ,
1904+ },
1905+ "spec" : map [string ]interface {}{
1906+ "cidrBlocks" : []interface {}{"10.0.0.0/16" },
1907+ },
1908+ }, nil , nil ),
1909+ generator .WithResource ("subnet" , map [string ]interface {}{
1910+ "apiVersion" : "ec2.services.k8s.aws/v1alpha1" ,
1911+ "kind" : "Subnet" ,
1912+ "metadata" : map [string ]interface {}{
1913+ "name" : "conditional-subnet" ,
1914+ "labels" : map [string ]interface {}{
1915+ "vpc-ready" : "${schema.status.vpcReady ? 'true' : 'false'}" ,
1916+ },
1917+ },
1918+ "spec" : map [string ]interface {}{
1919+ "cidrBlock" : "10.0.1.0/24" ,
1920+ "vpcID" : "${vpc.status.vpcID}" ,
1921+ },
1922+ }, nil , nil ),
1923+ },
1924+ wantErr : false ,
1925+ },
18051926 }
18061927
18071928 for _ , tt := range tests {
0 commit comments