InstallLatest installs an operator version with the most recent release tag
( ctx context.Context, crudClient client.Client, restConfig *rest.Config, releaseTag string, )
| 89 | |
| 90 | // InstallLatest installs an operator version with the most recent release tag |
| 91 | func InstallLatest( |
| 92 | ctx context.Context, |
| 93 | crudClient client.Client, |
| 94 | restConfig *rest.Config, |
| 95 | releaseTag string, |
| 96 | ) { |
| 97 | mostRecentReleasePath := "../../releases/cnpg-" + releaseTag + ".yaml" |
| 98 | |
| 99 | Eventually(func() error { |
| 100 | GinkgoWriter.Printf("installing: %s\n", mostRecentReleasePath) |
| 101 | |
| 102 | _, stderr, err := run.Unchecked("kubectl apply --server-side --force-conflicts -f " + mostRecentReleasePath) |
| 103 | if err != nil { |
| 104 | GinkgoWriter.Printf("stderr: %s\n", stderr) |
| 105 | } |
| 106 | |
| 107 | return err |
| 108 | }, 60).ShouldNot(HaveOccurred()) |
| 109 | |
| 110 | Eventually(func() error { |
| 111 | _, _, err := run.Unchecked( |
| 112 | "kubectl wait --for condition=established --timeout=60s " + |
| 113 | "crd/clusters.postgresql.cnpg.io") |
| 114 | return err |
| 115 | }, 150).ShouldNot(HaveOccurred()) |
| 116 | |
| 117 | Eventually(func() error { |
| 118 | mapping, err := crudClient.RESTMapper().RESTMapping( |
| 119 | schema.GroupKind{Group: apiv1.SchemeGroupVersion.Group, Kind: apiv1.ClusterKind}, |
| 120 | apiv1.SchemeGroupVersion.Version) |
| 121 | if err != nil { |
| 122 | return err |
| 123 | } |
| 124 | |
| 125 | GinkgoWriter.Printf("found mapping REST endpoint: %s\n", mapping.GroupVersionKind.String()) |
| 126 | |
| 127 | return nil |
| 128 | }, 150).ShouldNot(HaveOccurred()) |
| 129 | |
| 130 | Eventually(func() error { |
| 131 | _, _, err := run.Unchecked( |
| 132 | "kubectl wait --for=condition=Available --timeout=2m -n cnpg-system " + |
| 133 | "deployments cnpg-controller-manager") |
| 134 | return err |
| 135 | }, 150).ShouldNot(HaveOccurred()) |
| 136 | |
| 137 | // The OwnerReferencesPermissionEnforcement admission plugin (enabled on the |
| 138 | // test apiservers) resolves the owner GroupVersionKind through the apiserver's |
| 139 | // own RESTMapper, which is a different cache from the client RESTMapper checked |
| 140 | // above and refreshes from discovery on an interval (~30s). Until it picks up |
| 141 | // the freshly installed Cluster CRD, any object created with a blockOwnerDeletion |
| 142 | // owner reference to a Cluster is rejected with "no matches for kind Cluster", |
| 143 | // and the operator hits this the moment it creates the bootstrap Job. |
| 144 | // |
| 145 | // The check is only enforced for callers that are not cluster-admin, so probe |
| 146 | // while impersonating the operator's ServiceAccount: a privileged client (like |
| 147 | // the one used elsewhere in the suite) bypasses the plugin and would not gate |
| 148 | // on anything. |
no test coverage detected