Skip to content

Commit

Permalink
Add fetch_git_notes and adjust image version
Browse files Browse the repository at this point in the history
Fetch function added to get git notes and update callbacks for the repository. This improves the GitController by allowing to authenticate and fetch git note references. The image version of the main_container in `pulumi-operator-kubernetes/src/stack/service.rs` has been updated from 1.0.20 to 1.0.21 for the pulumi operator kubernetes job.
  • Loading branch information
jan-br committed Sep 25, 2023
1 parent 73ce942 commit 36c936b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions pulumi-operator-kubernetes-job/src/git/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
use git2::cert::{CertHostkey, SshHostKeyType};
use git2::{
build::RepoBuilder, CertificateCheckStatus, Cred, FetchOptions,
RemoteCallbacks,
RemoteCallbacks, Repository,
};
use k8s_openapi::{api::core::v1::Secret, ByteString};
use kube::core::ObjectMeta;
Expand Down Expand Up @@ -98,7 +98,18 @@ impl GitService {
}
builder.fetch_options(fo);

builder.clone(spec.repository.as_str(), Path::new("./source"))?;
let repo =
builder.clone(spec.repository.as_str(), Path::new("./source"))?;

let mut callback = RemoteCallbacks::new();

if let Some(auth) = &spec.auth {
let data = git_controller.get_secret(&namespace, &auth).await?;
git_controller.build_callback(auth, &data, &mut callback)?;
}

fetch_git_notes(&repo, callback)?;
panic!();

Ok::<&str, GitError>("./source")
}
Expand All @@ -113,6 +124,22 @@ impl GitService {
}
}

fn fetch_git_notes(
repo: &Repository,
callback: RemoteCallbacks,
) -> Result<(), git2::Error> {
let mut remote = repo.find_remote("origin")?;
let refspec = "refs/notes/*:refs/notes/*";

// Setup FetchOptions with your callback
let mut fetch_options = FetchOptions::new();
fetch_options.remote_callbacks(callback);

remote.fetch(&[refspec], Some(&mut fetch_options), None)?;

Ok(())
}

struct GitController {
kubernetes_service: Inst<KubernetesService>,
}
Expand Down
2 changes: 1 addition & 1 deletion pulumi-operator-kubernetes/src/stack/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl KubernetesPulumiStackService {

let mut main_container: Container = serde_json::from_value(json!({
"name": "pulumi",
"image": "ghcr.io/stromee/pulumi-operator/pulumi-operator-kubernetes-job:1.0.20",
"image": "ghcr.io/stromee/pulumi-operator/pulumi-operator-kubernetes-job:1.0.21",
"env": [{
"name": "PULUMI_STACK",
"value": name
Expand Down

0 comments on commit 36c936b

Please sign in to comment.