@@ -20,6 +20,7 @@ use kube::{
2020 core:: GroupVersionKind ,
2121 Api , Client ,
2222} ;
23+ use serde:: { Deserialize , Serialize } ;
2324use serde_json:: Value ;
2425use std:: { collections:: HashMap , ops:: Deref } ;
2526use tracing:: { debug, instrument} ;
@@ -37,20 +38,22 @@ enum WorkflowTemplateParsingError {
3738 MalformParameterSchema ( #[ from] serde_json:: Error ) ,
3839}
3940
40- #[ derive( Debug , Clone , SimpleObject , Eq , PartialEq ) ]
41+ #[ derive( Debug , Serialize , Deserialize , Default , Clone , SimpleObject , Eq , PartialEq ) ]
4142struct GitHubPath {
42- repo : String ,
4343 path : String ,
44+ repo_url : String ,
45+ target_revision : String ,
4446}
4547
46- impl GitHubPath {
47- fn new ( repo : impl Into < String > , path : impl Into < String > ) -> Self {
48- Self {
49- repo : repo. into ( ) ,
50- path : path. into ( ) ,
51- }
52- }
53- }
48+ // impl GitHubPath {
49+ // fn new(repo_url: impl Into<String>, path: impl Into<String>, target_revision: impl Into<String>) -> Self {
50+ // Self {
51+ // repo_url: repo_url.into(),
52+ // path: path.into(),
53+ // target_revision: target_revision.into(),
54+ // }
55+ // }
56+ // }
5457
5558/// A Template which specifies how to produce a [`Workflow`]
5659#[ derive( Debug , derive_more:: Deref , derive_more:: From ) ]
@@ -112,6 +115,7 @@ impl WorkflowTemplate {
112115 }
113116
114117 async fn template_url ( & self ) -> Result < GitHubPath , WorkflowTemplateParsingError > {
118+
115119 let instance = match self . metadata . labels . get ( "argocd.argoproj.io/instance" ) {
116120 Some ( val) => val,
117121 None => return Err ( WorkflowTemplateParsingError :: MissingInstanceLabel ) ,
@@ -126,25 +130,23 @@ impl WorkflowTemplate {
126130 ) ;
127131
128132 let obj = api. get ( & instance) . await . unwrap ( ) ;
129- let annotations = obj. metadata . annotations . clone ( ) . unwrap_or_default ( ) ;
130- println ! ( "Annotations: " ) ;
131- for ( key, value) in & annotations {
132- println ! ( "{}: {}" , key, value) ;
133- }
134- let path = match annotations. get ( "path" ) {
135- Some ( path) => path,
136- None => & String :: from ( "" ) ,
137- } ;
138- let repo = match self
139- . metadata
140- . annotations
141- . get ( "workflows.diamond.ac.uk/repository" )
142- {
143- Some ( repo) => repo,
144- None => & String :: from ( "" ) ,
133+ let group_annotations = obj. metadata . annotations . clone ( ) . unwrap_or_default ( ) ;
134+ let last_config =
135+ match group_annotations. get ( "kubectl.kubernetes.io/last-applied-configuration" ) {
136+ Some ( s) => s,
137+ None => "" ,
138+ } ;
139+
140+ let last_config_val: Value = serde_json:: from_str ( & last_config) ?;
141+ let source: GitHubPath = match last_config_val. get ( "spec" ) {
142+ Some ( val) => match val. get ( "source" ) {
143+ Some ( src) => serde_json:: from_value ( src. clone ( ) ) . unwrap ( ) ,
144+ None => GitHubPath { ..Default :: default ( ) }
145+ }
146+ None => GitHubPath { ..Default :: default ( ) }
145147 } ;
146148
147- Ok ( GitHubPath :: new ( repo , path ) )
149+ Ok ( source )
148150
149151 // let list = api.list(&ListParams::default()).await?;
150152 // for obj in list {
0 commit comments