MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / apply

Method apply

src/orchestratord/src/controller/materialize.rs:275–896  ·  view source on GitHub ↗
(
        &self,
        client: Client,
        mz: &Self::Resource,
        _metadata: &mut TraceMetadata,
    )

Source from the content-addressed store, hash-verified

273
274 #[instrument(fields(organization_name=mz.name_unchecked()))]
275 async fn apply(
276 &self,
277 client: Client,
278 mz: &Self::Resource,
279 _metadata: &mut TraceMetadata,
280 ) -> Result<Option<Action>, Self::Error> {
281 let mz_api: Api<Materialize> = Api::namespaced(client.clone(), &mz.namespace());
282 let balancer_api: Api<Balancer> = Api::namespaced(client.clone(), &mz.namespace());
283 let console_api: Api<Console> = Api::namespaced(client.clone(), &mz.namespace());
284 let secret_api: Api<Secret> = Api::namespaced(client.clone(), &mz.namespace());
285
286 let status = mz.status();
287 if mz.status.is_none() {
288 self.update_status(&mz_api, mz, status, true).await?;
289 // Updating the status should trigger a reconciliation
290 // which will include a status this time.
291 return Ok(None);
292 }
293
294 let backend_secret = secret_api.get(&mz.spec.backend_secret_name).await?;
295 let license_key_environment_id: Option<Uuid> = if let Some(license_key) = backend_secret
296 .data
297 .as_ref()
298 .and_then(|data| data.get("license_key"))
299 {
300 let license_key = validate(
301 str::from_utf8(&license_key.0)
302 .context("invalid utf8")?
303 .trim(),
304 )?;
305 let environment_id = license_key
306 .environment_id
307 .parse()
308 .context("invalid environment id in license key")?;
309 Some(environment_id)
310 } else {
311 if mz.meets_minimum_version(&V161) {
312 return Err(Error::Anyhow(anyhow::anyhow!(
313 "license_key is required when running in kubernetes",
314 )));
315 } else {
316 None
317 }
318 };
319
320 if mz.spec.request_rollout.is_nil() || mz.spec.environment_id.is_nil() {
321 let mut mz = mz.clone();
322 if mz.spec.request_rollout.is_nil() {
323 mz.spec.request_rollout = Uuid::new_v4();
324 }
325 if mz.spec.environment_id.is_nil() {
326 if let Some(environment_id) = license_key_environment_id {
327 if environment_id.is_nil() {
328 // this makes it easier to use a license key in
329 // development with no environment id set
330 mz.spec.environment_id = Uuid::new_v4();
331 } else {
332 mz.spec.environment_id = environment_id;

Callers

nothing calls this directly

Calls 15

nowFunction · 0.85
apply_resourceFunction · 0.85
wait_for_balancerFunction · 0.85
delete_resourceFunction · 0.85
parse_image_tagFunction · 0.85
issuer_ref_definedFunction · 0.85
resolved_dns_namesFunction · 0.85
is_noneMethod · 0.80
meets_minimum_versionMethod · 0.80
generate_hashMethod · 0.80

Tested by

no test coverage detected