CINXE.COM
Write a Composition Function in Go · Crossplane v1.16
<!doctype html><html lang=en class=color-toggle-hidden color-theme=light><head><meta charset=utf-8><script type="text/javascript"> ;window.NREUM||(NREUM={});NREUM.init={distributed_tracing:{enabled:true},privacy:{cookies_enabled:true},ajax:{deny_list:["bam.nr-data.net"]}}; window.NREUM||(NREUM={}),__nr_require=function(t,e,n){function r(n){if(!e[n]){var o=e[n]={exports:{}};t[n][0].call(o.exports,function(e){var o=t[n][1][e];return r(o||e)},o,o.exports)}return e[n].exports}if("function"==typeof __nr_require)return __nr_require;for(var o=0;o<n.length;o++)r(n[o]);return r}({1:[function(t,e,n){function r(t){try{s.console&&console.log(t)}catch(e){}}var o,i=t("ee"),a=t(32),s={};try{o=localStorage.getItem("__nr_flags").split(","),console&&"function"==typeof console.log&&(s.console=!0,o.indexOf("dev")!==-1&&(s.dev=!0),o.indexOf("nr_dev")!==-1&&(s.nrDev=!0))}catch(c){}s.nrDev&&i.on("internal-error",function(t){r(t.stack)}),s.dev&&i.on("fn-err",function(t,e,n){r(n.stack)}),s.dev&&(r("NR AGENT IN DEVELOPMENT MODE"),r("flags: "+a(s,function(t,e){return t}).join(", ")))},{}],2:[function(t,e,n){function r(t,e,n,r,s){try{l?l-=1:o(s||new UncaughtException(t,e,n),!0)}catch(f){try{i("ierr",[f,c.now(),!0])}catch(d){}}return"function"==typeof u&&u.apply(this,a(arguments))}function UncaughtException(t,e,n){this.message=t||"Uncaught error with no additional information",this.sourceURL=e,this.line=n}function o(t,e){var n=e?null:c.now();i("err",[t,n])}var i=t("handle"),a=t(33),s=t("ee"),c=t("loader"),f=t("gos"),u=window.onerror,d=!1,p="nr@seenError";if(!c.disabled){var l=0;c.features.err=!0,t(1),window.onerror=r;try{throw new Error}catch(h){"stack"in h&&(t(14),t(13),"addEventListener"in window&&t(7),c.xhrWrappable&&t(15),d=!0)}s.on("fn-start",function(t,e,n){d&&(l+=1)}),s.on("fn-err",function(t,e,n){d&&!n[p]&&(f(n,p,function(){return!0}),this.thrown=!0,o(n))}),s.on("fn-end",function(){d&&!this.thrown&&l>0&&(l-=1)}),s.on("internal-error",function(t){i("ierr",[t,c.now(),!0])})}},{}],3:[function(t,e,n){var r=t("loader");r.disabled||(r.features.ins=!0)},{}],4:[function(t,e,n){function r(){U++,L=g.hash,this[u]=y.now()}function o(){U--,g.hash!==L&&i(0,!0);var t=y.now();this[h]=~~this[h]+t-this[u],this[d]=t}function i(t,e){E.emit("newURL",[""+g,e])}function a(t,e){t.on(e,function(){this[e]=y.now()})}var s="-start",c="-end",f="-body",u="fn"+s,d="fn"+c,p="cb"+s,l="cb"+c,h="jsTime",m="fetch",v="addEventListener",w=window,g=w.location,y=t("loader");if(w[v]&&y.xhrWrappable&&!y.disabled){var x=t(11),b=t(12),E=t(9),R=t(7),O=t(14),T=t(8),P=t(15),S=t(10),M=t("ee"),N=M.get("tracer"),C=t(23);t(17),y.features.spa=!0;var L,U=0;M.on(u,r),b.on(p,r),S.on(p,r),M.on(d,o),b.on(l,o),S.on(l,o),M.buffer([u,d,"xhr-resolved"]),R.buffer([u]),O.buffer(["setTimeout"+c,"clearTimeout"+s,u]),P.buffer([u,"new-xhr","send-xhr"+s]),T.buffer([m+s,m+"-done",m+f+s,m+f+c]),E.buffer(["newURL"]),x.buffer([u]),b.buffer(["propagate",p,l,"executor-err","resolve"+s]),N.buffer([u,"no-"+u]),S.buffer(["new-jsonp","cb-start","jsonp-error","jsonp-end"]),a(T,m+s),a(T,m+"-done"),a(S,"new-jsonp"),a(S,"jsonp-end"),a(S,"cb-start"),E.on("pushState-end",i),E.on("replaceState-end",i),w[v]("hashchange",i,C(!0)),w[v]("load",i,C(!0)),w[v]("popstate",function(){i(0,U>1)},C(!0))}},{}],5:[function(t,e,n){function r(){var t=new PerformanceObserver(function(t,e){var n=t.getEntries();s(v,[n])});try{t.observe({entryTypes:["resource"]})}catch(e){}}function o(t){if(s(v,[window.performance.getEntriesByType(w)]),window.performance["c"+p])try{window.performance[h](m,o,!1)}catch(t){}else try{window.performance[h]("webkit"+m,o,!1)}catch(t){}}function i(t){}if(window.performance&&window.performance.timing&&window.performance.getEntriesByType){var a=t("ee"),s=t("handle"),c=t(14),f=t(13),u=t(6),d=t(23),p="learResourceTimings",l="addEventListener",h="removeEventListener",m="resourcetimingbufferfull",v="bstResource",w="resource",g="-start",y="-end",x="fn"+g,b="fn"+y,E="bstTimer",R="pushState",O=t("loader");if(!O.disabled){O.features.stn=!0,t(9),"addEventListener"in window&&t(7);var T=NREUM.o.EV;a.on(x,function(t,e){var n=t[0];n instanceof T&&(this.bstStart=O.now())}),a.on(b,function(t,e){var n=t[0];n instanceof T&&s("bst",[n,e,this.bstStart,O.now()])}),c.on(x,function(t,e,n){this.bstStart=O.now(),this.bstType=n}),c.on(b,function(t,e){s(E,[e,this.bstStart,O.now(),this.bstType])}),f.on(x,function(){this.bstStart=O.now()}),f.on(b,function(t,e){s(E,[e,this.bstStart,O.now(),"requestAnimationFrame"])}),a.on(R+g,function(t){this.time=O.now(),this.startPath=location.pathname+location.hash}),a.on(R+y,function(t){s("bstHist",[location.pathname+location.hash,this.startPath,this.time])}),u()?(s(v,[window.performance.getEntriesByType("resource")]),r()):l in window.performance&&(window.performance["c"+p]?window.performance[l](m,o,d(!1)):window.performance[l]("webkit"+m,o,d(!1))),document[l]("scroll",i,d(!1)),document[l]("keypress",i,d(!1)),document[l]("click",i,d(!1))}}},{}],6:[function(t,e,n){e.exports=function(){return"PerformanceObserver"in window&&"function"==typeof window.PerformanceObserver}},{}],7:[function(t,e,n){function r(t){for(var e=t;e&&!e.hasOwnProperty(u);)e=Object.getPrototypeOf(e);e&&o(e)}function o(t){s.inPlace(t,[u,d],"-",i)}function i(t,e){return t[1]}var a=t("ee").get("events"),s=t("wrap-function")(a,!0),c=t("gos"),f=XMLHttpRequest,u="addEventListener",d="removeEventListener";e.exports=a,"getPrototypeOf"in Object?(r(document),r(window),r(f.prototype)):f.prototype.hasOwnProperty(u)&&(o(window),o(f.prototype)),a.on(u+"-start",function(t,e){var n=t[1];if(null!==n&&("function"==typeof n||"object"==typeof n)){var r=c(n,"nr@wrapped",function(){function t(){if("function"==typeof n.handleEvent)return n.handleEvent.apply(n,arguments)}var e={object:t,"function":n}[typeof n];return e?s(e,"fn-",null,e.name||"anonymous"):n});this.wrapped=t[1]=r}}),a.on(d+"-start",function(t){t[1]=this.wrapped||t[1]})},{}],8:[function(t,e,n){function r(t,e,n){var r=t[e];"function"==typeof r&&(t[e]=function(){var t=i(arguments),e={};o.emit(n+"before-start",[t],e);var a;e[m]&&e[m].dt&&(a=e[m].dt);var s=r.apply(this,t);return o.emit(n+"start",[t,a],s),s.then(function(t){return o.emit(n+"end",[null,t],s),t},function(t){throw o.emit(n+"end",[t],s),t})})}var o=t("ee").get("fetch"),i=t(33),a=t(32);e.exports=o;var s=window,c="fetch-",f=c+"body-",u=["arrayBuffer","blob","json","text","formData"],d=s.Request,p=s.Response,l=s.fetch,h="prototype",m="nr@context";d&&p&&l&&(a(u,function(t,e){r(d[h],e,f),r(p[h],e,f)}),r(s,"fetch",c),o.on(c+"end",function(t,e){var n=this;if(e){var r=e.headers.get("content-length");null!==r&&(n.rxSize=r),o.emit(c+"done",[null,e],n)}else o.emit(c+"done",[t],n)}))},{}],9:[function(t,e,n){var r=t("ee").get("history"),o=t("wrap-function")(r);e.exports=r;var i=window.history&&window.history.constructor&&window.history.constructor.prototype,a=window.history;i&&i.pushState&&i.replaceState&&(a=i),o.inPlace(a,["pushState","replaceState"],"-")},{}],10:[function(t,e,n){function r(t){function e(){f.emit("jsonp-end",[],l),t.removeEventListener("load",e,c(!1)),t.removeEventListener("error",n,c(!1))}function n(){f.emit("jsonp-error",[],l),f.emit("jsonp-end",[],l),t.removeEventListener("load",e,c(!1)),t.removeEventListener("error",n,c(!1))}var r=t&&"string"==typeof t.nodeName&&"script"===t.nodeName.toLowerCase();if(r){var o="function"==typeof t.addEventListener;if(o){var a=i(t.src);if(a){var d=s(a),p="function"==typeof d.parent[d.key];if(p){var l={};u.inPlace(d.parent,[d.key],"cb-",l),t.addEventListener("load",e,c(!1)),t.addEventListener("error",n,c(!1)),f.emit("new-jsonp",[t.src],l)}}}}}function o(){return"addEventListener"in window}function i(t){var e=t.match(d);return e?e[1]:null}function a(t,e){var n=t.match(l),r=n[1],o=n[3];return o?a(o,e[r]):e[r]}function s(t){var e=t.match(p);return e&&e.length>=3?{key:e[2],parent:a(e[1],window)}:{key:t,parent:window}}var c=t(23),f=t("ee").get("jsonp"),u=t("wrap-function")(f);if(e.exports=f,o()){var d=/[?&](?:callback|cb)=([^&#]+)/,p=/(.*)\.([^.]+)/,l=/^(\w+)(\.|$)(.*)$/,h=["appendChild","insertBefore","replaceChild"];Node&&Node.prototype&&Node.prototype.appendChild?u.inPlace(Node.prototype,h,"dom-"):(u.inPlace(HTMLElement.prototype,h,"dom-"),u.inPlace(HTMLHeadElement.prototype,h,"dom-"),u.inPlace(HTMLBodyElement.prototype,h,"dom-")),f.on("dom-start",function(t){r(t[0])})}},{}],11:[function(t,e,n){var r=t("ee").get("mutation"),o=t("wrap-function")(r),i=NREUM.o.MO;e.exports=r,i&&(window.MutationObserver=function(t){return this instanceof i?new i(o(t,"fn-")):i.apply(this,arguments)},MutationObserver.prototype=i.prototype)},{}],12:[function(t,e,n){function r(t){var e=i.context(),n=s(t,"executor-",e,null,!1),r=new f(n);return i.context(r).getCtx=function(){return e},r}var o=t("wrap-function"),i=t("ee").get("promise"),a=t("ee").getOrSetContext,s=o(i),c=t(32),f=NREUM.o.PR;e.exports=i,f&&(window.Promise=r,["all","race"].forEach(function(t){var e=f[t];f[t]=function(n){function r(t){return function(){i.emit("propagate",[null,!o],a,!1,!1),o=o||!t}}var o=!1;c(n,function(e,n){Promise.resolve(n).then(r("all"===t),r(!1))});var a=e.apply(f,arguments),s=f.resolve(a);return s}}),["resolve","reject"].forEach(function(t){var e=f[t];f[t]=function(t){var n=e.apply(f,arguments);return t!==n&&i.emit("propagate",[t,!0],n,!1,!1),n}}),f.prototype["catch"]=function(t){return this.then(null,t)},f.prototype=Object.create(f.prototype,{constructor:{value:r}}),c(Object.getOwnPropertyNames(f),function(t,e){try{r[e]=f[e]}catch(n){}}),o.wrapInPlace(f.prototype,"then",function(t){return function(){var e=this,n=o.argsToArray.apply(this,arguments),r=a(e);r.promise=e,n[0]=s(n[0],"cb-",r,null,!1),n[1]=s(n[1],"cb-",r,null,!1);var c=t.apply(this,n);return r.nextPromise=c,i.emit("propagate",[e,!0],c,!1,!1),c}}),i.on("executor-start",function(t){t[0]=s(t[0],"resolve-",this,null,!1),t[1]=s(t[1],"resolve-",this,null,!1)}),i.on("executor-err",function(t,e,n){t[1](n)}),i.on("cb-end",function(t,e,n){i.emit("propagate",[n,!0],this.nextPromise,!1,!1)}),i.on("propagate",function(t,e,n){this.getCtx&&!e||(this.getCtx=function(){if(t instanceof Promise)var e=i.context(t);return e&&e.getCtx?e.getCtx():this})}),r.toString=function(){return""+f})},{}],13:[function(t,e,n){var r=t("ee").get("raf"),o=t("wrap-function")(r),i="equestAnimationFrame";e.exports=r,o.inPlace(window,["r"+i,"mozR"+i,"webkitR"+i,"msR"+i],"raf-"),r.on("raf-start",function(t){t[0]=o(t[0],"fn-")})},{}],14:[function(t,e,n){function r(t,e,n){t[0]=a(t[0],"fn-",null,n)}function o(t,e,n){this.method=n,this.timerDuration=isNaN(t[1])?0:+t[1],t[0]=a(t[0],"fn-",this,n)}var i=t("ee").get("timer"),a=t("wrap-function")(i),s="setTimeout",c="setInterval",f="clearTimeout",u="-start",d="-";e.exports=i,a.inPlace(window,[s,"setImmediate"],s+d),a.inPlace(window,[c],c+d),a.inPlace(window,[f,"clearImmediate"],f+d),i.on(c+u,r),i.on(s+u,o)},{}],15:[function(t,e,n){function r(t,e){d.inPlace(e,["onreadystatechange"],"fn-",s)}function o(){var t=this,e=u.context(t);t.readyState>3&&!e.resolved&&(e.resolved=!0,u.emit("xhr-resolved",[],t)),d.inPlace(t,y,"fn-",s)}function i(t){x.push(t),m&&(E?E.then(a):w?w(a):(R=-R,O.data=R))}function a(){for(var t=0;t<x.length;t++)r([],x[t]);x.length&&(x=[])}function s(t,e){return e}function c(t,e){for(var n in t)e[n]=t[n];return e}t(7);var f=t("ee"),u=f.get("xhr"),d=t("wrap-function")(u),p=t(23),l=NREUM.o,h=l.XHR,m=l.MO,v=l.PR,w=l.SI,g="readystatechange",y=["onload","onerror","onabort","onloadstart","onloadend","onprogress","ontimeout"],x=[];e.exports=u;var b=window.XMLHttpRequest=function(t){var e=new h(t);try{u.emit("new-xhr",[e],e),e.addEventListener(g,o,p(!1))}catch(n){try{u.emit("internal-error",[n])}catch(r){}}return e};if(c(h,b),b.prototype=h.prototype,d.inPlace(b.prototype,["open","send"],"-xhr-",s),u.on("send-xhr-start",function(t,e){r(t,e),i(e)}),u.on("open-xhr-start",r),m){var E=v&&v.resolve();if(!w&&!v){var R=1,O=document.createTextNode(R);new m(a).observe(O,{characterData:!0})}}else f.on("fn-end",function(t){t[0]&&t[0].type===g||a()})},{}],16:[function(t,e,n){function r(t){if(!s(t))return null;var e=window.NREUM;if(!e.loader_config)return null;var n=(e.loader_config.accountID||"").toString()||null,r=(e.loader_config.agentID||"").toString()||null,f=(e.loader_config.trustKey||"").toString()||null;if(!n||!r)return null;var h=l.generateSpanId(),m=l.generateTraceId(),v=Date.now(),w={spanId:h,traceId:m,timestamp:v};return(t.sameOrigin||c(t)&&p())&&(w.traceContextParentHeader=o(h,m),w.traceContextStateHeader=i(h,v,n,r,f)),(t.sameOrigin&&!u()||!t.sameOrigin&&c(t)&&d())&&(w.newrelicHeader=a(h,m,v,n,r,f)),w}function o(t,e){return"00-"+e+"-"+t+"-01"}function i(t,e,n,r,o){var i=0,a="",s=1,c="",f="";return o+"@nr="+i+"-"+s+"-"+n+"-"+r+"-"+t+"-"+a+"-"+c+"-"+f+"-"+e}function a(t,e,n,r,o,i){var a="btoa"in window&&"function"==typeof window.btoa;if(!a)return null;var s={v:[0,1],d:{ty:"Browser",ac:r,ap:o,id:t,tr:e,ti:n}};return i&&r!==i&&(s.d.tk=i),btoa(JSON.stringify(s))}function s(t){return f()&&c(t)}function c(t){var e=!1,n={};if("init"in NREUM&&"distributed_tracing"in NREUM.init&&(n=NREUM.init.distributed_tracing),t.sameOrigin)e=!0;else if(n.allowed_origins instanceof Array)for(var r=0;r<n.allowed_origins.length;r++){var o=h(n.allowed_origins[r]);if(t.hostname===o.hostname&&t.protocol===o.protocol&&t.port===o.port){e=!0;break}}return e}function f(){return"init"in NREUM&&"distributed_tracing"in NREUM.init&&!!NREUM.init.distributed_tracing.enabled}function u(){return"init"in NREUM&&"distributed_tracing"in NREUM.init&&!!NREUM.init.distributed_tracing.exclude_newrelic_header}function d(){return"init"in NREUM&&"distributed_tracing"in NREUM.init&&NREUM.init.distributed_tracing.cors_use_newrelic_header!==!1}function p(){return"init"in NREUM&&"distributed_tracing"in NREUM.init&&!!NREUM.init.distributed_tracing.cors_use_tracecontext_headers}var l=t(29),h=t(18);e.exports={generateTracePayload:r,shouldGenerateTrace:s}},{}],17:[function(t,e,n){function r(t){var e=this.params,n=this.metrics;if(!this.ended){this.ended=!0;for(var r=0;r<p;r++)t.removeEventListener(d[r],this.listener,!1);e.aborted||(n.duration=a.now()-this.startTime,this.loadCaptureCalled||4!==t.readyState?null==e.status&&(e.status=0):i(this,t),n.cbTime=this.cbTime,s("xhr",[e,n,this.startTime,this.endTime,"xhr"],this))}}function o(t,e){var n=c(e),r=t.params;r.hostname=n.hostname,r.port=n.port,r.protocol=n.protocol,r.host=n.hostname+":"+n.port,r.pathname=n.pathname,t.parsedOrigin=n,t.sameOrigin=n.sameOrigin}function i(t,e){t.params.status=e.status;var n=v(e,t.lastSize);if(n&&(t.metrics.rxSize=n),t.sameOrigin){var r=e.getResponseHeader("X-NewRelic-App-Data");r&&(t.params.cat=r.split(", ").pop())}t.loadCaptureCalled=!0}var a=t("loader");if(a.xhrWrappable&&!a.disabled){var s=t("handle"),c=t(18),f=t(16).generateTracePayload,u=t("ee"),d=["load","error","abort","timeout"],p=d.length,l=t("id"),h=t(24),m=t(22),v=t(19),w=t(23),g=NREUM.o.REQ,y=window.XMLHttpRequest;a.features.xhr=!0,t(15),t(8),u.on("new-xhr",function(t){var e=this;e.totalCbs=0,e.called=0,e.cbTime=0,e.end=r,e.ended=!1,e.xhrGuids={},e.lastSize=null,e.loadCaptureCalled=!1,e.params=this.params||{},e.metrics=this.metrics||{},t.addEventListener("load",function(n){i(e,t)},w(!1)),h&&(h>34||h<10)||t.addEventListener("progress",function(t){e.lastSize=t.loaded},w(!1))}),u.on("open-xhr-start",function(t){this.params={method:t[0]},o(this,t[1]),this.metrics={}}),u.on("open-xhr-end",function(t,e){"loader_config"in NREUM&&"xpid"in NREUM.loader_config&&this.sameOrigin&&e.setRequestHeader("X-NewRelic-ID",NREUM.loader_config.xpid);var n=f(this.parsedOrigin);if(n){var r=!1;n.newrelicHeader&&(e.setRequestHeader("newrelic",n.newrelicHeader),r=!0),n.traceContextParentHeader&&(e.setRequestHeader("traceparent",n.traceContextParentHeader),n.traceContextStateHeader&&e.setRequestHeader("tracestate",n.traceContextStateHeader),r=!0),r&&(this.dt=n)}}),u.on("send-xhr-start",function(t,e){var n=this.metrics,r=t[0],o=this;if(n&&r){var i=m(r);i&&(n.txSize=i)}this.startTime=a.now(),this.listener=function(t){try{"abort"!==t.type||o.loadCaptureCalled||(o.params.aborted=!0),("load"!==t.type||o.called===o.totalCbs&&(o.onloadCalled||"function"!=typeof e.onload))&&o.end(e)}catch(n){try{u.emit("internal-error",[n])}catch(r){}}};for(var s=0;s<p;s++)e.addEventListener(d[s],this.listener,w(!1))}),u.on("xhr-cb-time",function(t,e,n){this.cbTime+=t,e?this.onloadCalled=!0:this.called+=1,this.called!==this.totalCbs||!this.onloadCalled&&"function"==typeof n.onload||this.end(n)}),u.on("xhr-load-added",function(t,e){var n=""+l(t)+!!e;this.xhrGuids&&!this.xhrGuids[n]&&(this.xhrGuids[n]=!0,this.totalCbs+=1)}),u.on("xhr-load-removed",function(t,e){var n=""+l(t)+!!e;this.xhrGuids&&this.xhrGuids[n]&&(delete this.xhrGuids[n],this.totalCbs-=1)}),u.on("xhr-resolved",function(){this.endTime=a.now()}),u.on("addEventListener-end",function(t,e){e instanceof y&&"load"===t[0]&&u.emit("xhr-load-added",[t[1],t[2]],e)}),u.on("removeEventListener-end",function(t,e){e instanceof y&&"load"===t[0]&&u.emit("xhr-load-removed",[t[1],t[2]],e)}),u.on("fn-start",function(t,e,n){e instanceof y&&("onload"===n&&(this.onload=!0),("load"===(t[0]&&t[0].type)||this.onload)&&(this.xhrCbStart=a.now()))}),u.on("fn-end",function(t,e){this.xhrCbStart&&u.emit("xhr-cb-time",[a.now()-this.xhrCbStart,this.onload,e],e)}),u.on("fetch-before-start",function(t){function e(t,e){var n=!1;return e.newrelicHeader&&(t.set("newrelic",e.newrelicHeader),n=!0),e.traceContextParentHeader&&(t.set("traceparent",e.traceContextParentHeader),e.traceContextStateHeader&&t.set("tracestate",e.traceContextStateHeader),n=!0),n}var n,r=t[1]||{};"string"==typeof t[0]?n=t[0]:t[0]&&t[0].url?n=t[0].url:window.URL&&t[0]&&t[0]instanceof URL&&(n=t[0].href),n&&(this.parsedOrigin=c(n),this.sameOrigin=this.parsedOrigin.sameOrigin);var o=f(this.parsedOrigin);if(o&&(o.newrelicHeader||o.traceContextParentHeader))if("string"==typeof t[0]||window.URL&&t[0]&&t[0]instanceof URL){var i={};for(var a in r)i[a]=r[a];i.headers=new Headers(r.headers||{}),e(i.headers,o)&&(this.dt=o),t.length>1?t[1]=i:t.push(i)}else t[0]&&t[0].headers&&e(t[0].headers,o)&&(this.dt=o)}),u.on("fetch-start",function(t,e){this.params={},this.metrics={},this.startTime=a.now(),this.dt=e,t.length>=1&&(this.target=t[0]),t.length>=2&&(this.opts=t[1]);var n,r=this.opts||{},i=this.target;"string"==typeof i?n=i:"object"==typeof i&&i instanceof g?n=i.url:window.URL&&"object"==typeof i&&i instanceof URL&&(n=i.href),o(this,n);var s=(""+(i&&i instanceof g&&i.method||r.method||"GET")).toUpperCase();this.params.method=s,this.txSize=m(r.body)||0}),u.on("fetch-done",function(t,e){this.endTime=a.now(),this.params||(this.params={}),this.params.status=e?e.status:0;var n;"string"==typeof this.rxSize&&this.rxSize.length>0&&(n=+this.rxSize);var r={txSize:this.txSize,rxSize:n,duration:a.now()-this.startTime};s("xhr",[this.params,r,this.startTime,this.endTime,"fetch"],this)})}},{}],18:[function(t,e,n){var r={};e.exports=function(t){if(t in r)return r[t];var e=document.createElement("a"),n=window.location,o={};e.href=t,o.port=e.port;var i=e.href.split("://");!o.port&&i[1]&&(o.port=i[1].split("/")[0].split("@").pop().split(":")[1]),o.port&&"0"!==o.port||(o.port="https"===i[0]?"443":"80"),o.hostname=e.hostname||n.hostname,o.pathname=e.pathname,o.protocol=i[0],"/"!==o.pathname.charAt(0)&&(o.pathname="/"+o.pathname);var a=!e.protocol||":"===e.protocol||e.protocol===n.protocol,s=e.hostname===document.domain&&e.port===n.port;return o.sameOrigin=a&&(!e.hostname||s),"/"===o.pathname&&(r[t]=o),o}},{}],19:[function(t,e,n){function r(t,e){var n=t.responseType;return"json"===n&&null!==e?e:"arraybuffer"===n||"blob"===n||"json"===n?o(t.response):"text"===n||""===n||void 0===n?o(t.responseText):void 0}var o=t(22);e.exports=r},{}],20:[function(t,e,n){function r(){}function o(t,e,n,r){return function(){return u.recordSupportability("API/"+e+"/called"),i(t+e,[f.now()].concat(s(arguments)),n?null:this,r),n?void 0:this}}var i=t("handle"),a=t(32),s=t(33),c=t("ee").get("tracer"),f=t("loader"),u=t(25),d=NREUM;"undefined"==typeof window.newrelic&&(newrelic=d);var p=["setPageViewName","setCustomAttribute","setErrorHandler","finished","addToTrace","inlineHit","addRelease"],l="api-",h=l+"ixn-";a(p,function(t,e){d[e]=o(l,e,!0,"api")}),d.addPageAction=o(l,"addPageAction",!0),d.setCurrentRouteName=o(l,"routeName",!0),e.exports=newrelic,d.interaction=function(){return(new r).get()};var m=r.prototype={createTracer:function(t,e){var n={},r=this,o="function"==typeof e;return i(h+"tracer",[f.now(),t,n],r),function(){if(c.emit((o?"":"no-")+"fn-start",[f.now(),r,o],n),o)try{return e.apply(this,arguments)}catch(t){throw c.emit("fn-err",[arguments,this,t],n),t}finally{c.emit("fn-end",[f.now()],n)}}}};a("actionText,setName,setAttribute,save,ignore,onEnd,getContext,end,get".split(","),function(t,e){m[e]=o(h,e)}),newrelic.noticeError=function(t,e){"string"==typeof t&&(t=new Error(t)),u.recordSupportability("API/noticeError/called"),i("err",[t,f.now(),!1,e])}},{}],21:[function(t,e,n){function r(t){if(NREUM.init){for(var e=NREUM.init,n=t.split("."),r=0;r<n.length-1;r++)if(e=e[n[r]],"object"!=typeof e)return;return e=e[n[n.length-1]]}}e.exports={getConfiguration:r}},{}],22:[function(t,e,n){e.exports=function(t){if("string"==typeof t&&t.length)return t.length;if("object"==typeof t){if("undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer&&t.byteLength)return t.byteLength;if("undefined"!=typeof Blob&&t instanceof Blob&&t.size)return t.size;if(!("undefined"!=typeof FormData&&t instanceof FormData))try{return JSON.stringify(t).length}catch(e){return}}}},{}],23:[function(t,e,n){var r=!1;try{var o=Object.defineProperty({},"passive",{get:function(){r=!0}});window.addEventListener("testPassive",null,o),window.removeEventListener("testPassive",null,o)}catch(i){}e.exports=function(t){return r?{passive:!0,capture:!!t}:!!t}},{}],24:[function(t,e,n){var r=0,o=navigator.userAgent.match(/Firefox[\/\s](\d+\.\d+)/);o&&(r=+o[1]),e.exports=r},{}],25:[function(t,e,n){function r(t,e){var n=[a,t,{name:t},e];return i("storeMetric",n,null,"api"),n}function o(t,e){var n=[s,t,{name:t},e];return i("storeEventMetrics",n,null,"api"),n}var i=t("handle"),a="sm",s="cm";e.exports={constants:{SUPPORTABILITY_METRIC:a,CUSTOM_METRIC:s},recordSupportability:r,recordCustom:o}},{}],26:[function(t,e,n){function r(){return s.exists&&performance.now?Math.round(performance.now()):(i=Math.max((new Date).getTime(),i))-a}function o(){return i}var i=(new Date).getTime(),a=i,s=t(34);e.exports=r,e.exports.offset=a,e.exports.getLastTimestamp=o},{}],27:[function(t,e,n){function r(t){return!(!t||!t.protocol||"file:"===t.protocol)}e.exports=r},{}],28:[function(t,e,n){function r(t,e){var n=t.getEntries();n.forEach(function(t){"first-paint"===t.name?p("timing",["fp",Math.floor(t.startTime)]):"first-contentful-paint"===t.name&&p("timing",["fcp",Math.floor(t.startTime)])})}function o(t,e){var n=t.getEntries();if(n.length>0){var r=n[n.length-1];if(c&&c<r.startTime)return;p("lcp",[r])}}function i(t){t.getEntries().forEach(function(t){t.hadRecentInput||p("cls",[t])})}function a(t){if(t instanceof v&&!g){var e=Math.round(t.timeStamp),n={type:t.type};e<=l.now()?n.fid=l.now()-e:e>l.offset&&e<=Date.now()?(e-=l.offset,n.fid=l.now()-e):e=l.now(),g=!0,p("timing",["fi",e,n])}}function s(t){"hidden"===t&&(c=l.now(),p("pageHide",[c]))}if(!("init"in NREUM&&"page_view_timing"in NREUM.init&&"enabled"in NREUM.init.page_view_timing&&NREUM.init.page_view_timing.enabled===!1)){var c,f,u,d,p=t("handle"),l=t("loader"),h=t(31),m=t(23),v=NREUM.o.EV;if("PerformanceObserver"in window&&"function"==typeof window.PerformanceObserver){f=new PerformanceObserver(r);try{f.observe({entryTypes:["paint"]})}catch(w){}u=new PerformanceObserver(o);try{u.observe({entryTypes:["largest-contentful-paint"]})}catch(w){}d=new PerformanceObserver(i);try{d.observe({type:"layout-shift",buffered:!0})}catch(w){}}if("addEventListener"in document){var g=!1,y=["click","keydown","mousedown","pointerdown","touchstart"];y.forEach(function(t){document.addEventListener(t,a,m(!1))})}h(s)}},{}],29:[function(t,e,n){function r(){function t(){return e?15&e[n++]:16*Math.random()|0}var e=null,n=0,r=window.crypto||window.msCrypto;r&&r.getRandomValues&&(e=r.getRandomValues(new Uint8Array(31)));for(var o,i="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",a="",s=0;s<i.length;s++)o=i[s],"x"===o?a+=t().toString(16):"y"===o?(o=3&t()|8,a+=o.toString(16)):a+=o;return a}function o(){return a(16)}function i(){return a(32)}function a(t){function e(){return n?15&n[r++]:16*Math.random()|0}var n=null,r=0,o=window.crypto||window.msCrypto;o&&o.getRandomValues&&Uint8Array&&(n=o.getRandomValues(new Uint8Array(31)));for(var i=[],a=0;a<t;a++)i.push(e().toString(16));return i.join("")}e.exports={generateUuid:r,generateSpanId:o,generateTraceId:i}},{}],30:[function(t,e,n){function r(t,e){if(!o)return!1;if(t!==o)return!1;if(!e)return!0;if(!i)return!1;for(var n=i.split("."),r=e.split("."),a=0;a<r.length;a++)if(r[a]!==n[a])return!1;return!0}var o=null,i=null,a=/Version\/(\S+)\s+Safari/;if(navigator.userAgent){var s=navigator.userAgent,c=s.match(a);c&&s.indexOf("Chrome")===-1&&s.indexOf("Chromium")===-1&&(o="Safari",i=c[1])}e.exports={agent:o,version:i,match:r}},{}],31:[function(t,e,n){function r(t){function e(){t(s&&document[s]?document[s]:document[i]?"hidden":"visible")}"addEventListener"in document&&a&&document.addEventListener(a,e,o(!1))}var o=t(23);e.exports=r;var i,a,s;"undefined"!=typeof document.hidden?(i="hidden",a="visibilitychange",s="visibilityState"):"undefined"!=typeof document.msHidden?(i="msHidden",a="msvisibilitychange"):"undefined"!=typeof document.webkitHidden&&(i="webkitHidden",a="webkitvisibilitychange",s="webkitVisibilityState")},{}],32:[function(t,e,n){function r(t,e){var n=[],r="",i=0;for(r in t)o.call(t,r)&&(n[i]=e(r,t[r]),i+=1);return n}var o=Object.prototype.hasOwnProperty;e.exports=r},{}],33:[function(t,e,n){function r(t,e,n){e||(e=0),"undefined"==typeof n&&(n=t?t.length:0);for(var r=-1,o=n-e||0,i=Array(o<0?0:o);++r<o;)i[r]=t[e+r];return i}e.exports=r},{}],34:[function(t,e,n){e.exports={exists:"undefined"!=typeof window.performance&&window.performance.timing&&"undefined"!=typeof window.performance.timing.navigationStart}},{}],ee:[function(t,e,n){function r(){}function o(t){function e(t){return t&&t instanceof r?t:t?f(t,c,a):a()}function n(n,r,o,i,a){if(a!==!1&&(a=!0),!l.aborted||i){t&&a&&t(n,r,o);for(var s=e(o),c=m(n),f=c.length,u=0;u<f;u++)c[u].apply(s,r);var p=d[y[n]];return p&&p.push([x,n,r,s]),s}}function i(t,e){g[t]=m(t).concat(e)}function h(t,e){var n=g[t];if(n)for(var r=0;r<n.length;r++)n[r]===e&&n.splice(r,1)}function m(t){return g[t]||[]}function v(t){return p[t]=p[t]||o(n)}function w(t,e){l.aborted||u(t,function(t,n){e=e||"feature",y[n]=e,e in d||(d[e]=[])})}var g={},y={},x={on:i,addEventListener:i,removeEventListener:h,emit:n,get:v,listeners:m,context:e,buffer:w,abort:s,aborted:!1};return x}function i(t){return f(t,c,a)}function a(){return new r}function s(){(d.api||d.feature)&&(l.aborted=!0,d=l.backlog={})}var c="nr@context",f=t("gos"),u=t(32),d={},p={},l=e.exports=o();e.exports.getOrSetContext=i,l.backlog=d},{}],gos:[function(t,e,n){function r(t,e,n){if(o.call(t,e))return t[e];var r=n();if(Object.defineProperty&&Object.keys)try{return Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!1}),r}catch(i){}return t[e]=r,r}var o=Object.prototype.hasOwnProperty;e.exports=r},{}],handle:[function(t,e,n){function r(t,e,n,r){o.buffer([t],r),o.emit(t,e,n)}var o=t("ee").get("handle");e.exports=r,r.ee=o},{}],id:[function(t,e,n){function r(t){var e=typeof t;return!t||"object"!==e&&"function"!==e?-1:t===window?0:a(t,i,function(){return o++})}var o=1,i="nr@id",a=t("gos");e.exports=r},{}],loader:[function(t,e,n){function r(){if(!P++){var t=T.info=NREUM.info,e=v.getElementsByTagName("script")[0];if(setTimeout(f.abort,3e4),!(t&&t.licenseKey&&t.applicationID&&e))return f.abort();c(R,function(e,n){t[e]||(t[e]=n)});var n=a();s("mark",["onload",n+T.offset],null,"api"),s("timing",["load",n]);var r=v.createElement("script");0===t.agent.indexOf("http://")||0===t.agent.indexOf("https://")?r.src=t.agent:r.src=h+"://"+t.agent,e.parentNode.insertBefore(r,e)}}function o(){"complete"===v.readyState&&i()}function i(){s("mark",["domContent",a()+T.offset],null,"api")}var a=t(26),s=t("handle"),c=t(32),f=t("ee"),u=t(30),d=t(27),p=t(21),l=t(23),h=p.getConfiguration("ssl")===!1?"http":"https",m=window,v=m.document,w="addEventListener",g="attachEvent",y=m.XMLHttpRequest,x=y&&y.prototype,b=!d(m.location);NREUM.o={ST:setTimeout,SI:m.setImmediate,CT:clearTimeout,XHR:y,REQ:m.Request,EV:m.Event,PR:m.Promise,MO:m.MutationObserver};var E=""+location,R={beacon:"bam.nr-data.net",errorBeacon:"bam.nr-data.net",agent:"js-agent.newrelic.com/nr-spa-1212.min.js"},O=y&&x&&x[w]&&!/CriOS/.test(navigator.userAgent),T=e.exports={offset:a.getLastTimestamp(),now:a,origin:E,features:{},xhrWrappable:O,userAgent:u,disabled:b};if(!b){t(20),t(28),v[w]?(v[w]("DOMContentLoaded",i,l(!1)),m[w]("load",r,l(!1))):(v[g]("onreadystatechange",o),m[g]("onload",r)),s("mark",["firstbyte",a.getLastTimestamp()],null,"api");var P=0}},{}],"wrap-function":[function(t,e,n){function r(t,e){function n(e,n,r,c,f){function nrWrapper(){var i,a,u,p;try{a=this,i=d(arguments),u="function"==typeof r?r(i,a):r||{}}catch(l){o([l,"",[i,a,c],u],t)}s(n+"start",[i,a,c],u,f);try{return p=e.apply(a,i)}catch(h){throw s(n+"err",[i,a,h],u,f),h}finally{s(n+"end",[i,a,p],u,f)}}return a(e)?e:(n||(n=""),nrWrapper[p]=e,i(e,nrWrapper,t),nrWrapper)}function r(t,e,r,o,i){r||(r="");var s,c,f,u="-"===r.charAt(0);for(f=0;f<e.length;f++)c=e[f],s=t[c],a(s)||(t[c]=n(s,u?c+r:r,o,c,i))}function s(n,r,i,a){if(!h||e){var s=h;h=!0;try{t.emit(n,r,i,e,a)}catch(c){o([c,n,r,i],t)}h=s}}return t||(t=u),n.inPlace=r,n.flag=p,n}function o(t,e){e||(e=u);try{e.emit("internal-error",t)}catch(n){}}function i(t,e,n){if(Object.defineProperty&&Object.keys)try{var r=Object.keys(t);return r.forEach(function(n){Object.defineProperty(e,n,{get:function(){return t[n]},set:function(e){return t[n]=e,e}})}),e}catch(i){o([i],n)}for(var a in t)l.call(t,a)&&(e[a]=t[a]);return e}function a(t){return!(t&&t instanceof Function&&t.apply&&!t[p])}function s(t,e){var n=e(t);return n[p]=t,i(t,n,u),n}function c(t,e,n){var r=t[e];t[e]=s(r,n)}function f(){for(var t=arguments.length,e=new Array(t),n=0;n<t;++n)e[n]=arguments[n];return e}var u=t("ee"),d=t(33),p="nr@original",l=Object.prototype.hasOwnProperty,h=!1;e.exports=r,e.exports.wrapFunction=s,e.exports.wrapInPlace=c,e.exports.argsToArray=f},{}]},{},["loader",2,17,5,3,4]); ;NREUM.loader_config={accountID:"3768898",trustKey:"3768898",agentID:"1134285132",licenseKey:"NRJS-2bc9f9fb1efc463f27c",applicationID:"1134285132"} ;NREUM.info={beacon:"bam.nr-data.net",errorBeacon:"bam.nr-data.net",licenseKey:"NRJS-2bc9f9fb1efc463f27c",applicationID:"1134285132",sa:1} newrelic.addRelease("", "Remove-ControllerConfig-r-production-4dd74f6-17d951-17d94f"); </script><meta name=viewport content="width=device-width,initial-scale=1"><meta name=author content="Crossplane Community"><meta name=color-scheme content="light dark"><meta name=docsearch:language content="en"><meta name=generator content="Hugo 0.119.0"><link rel=preload href=/fonts/Avenir-Roman.woff2 as=font type=font/woff2 crossorigin><meta property="og:image" content="/img/crossplane-logo-og.webp"><meta property="twitter:card" content="/img/crossplane-logo-og.webp"><meta property="og:image:width" content="600"><meta property="og:image:height" content="199"><meta property="og:image:alt" content="Crossplane name and popsicle logo"><meta property="twitter:image:alt" content="Crossplane name and popsicle logo"><meta property="og:type" content="website"><meta name=twitter:site content="@crossplane_io"><meta property="og:site_name" content="Crossplane Documentation"><meta name=description content="Composition functions allow you to template resources using Go"><meta property="og:url" content="https://docs.crossplane.io/v1.16/guides/write-a-composition-function-in-go/"><meta name=docsearch:modified content="May 18, 2024"><meta name=docsearch:version content="1.16"><title>Write a Composition Function in Go · Crossplane v1.16</title><link rel=canonical href=https://docs.crossplane.io/latest/guides/write-a-composition-function-in-go/><script>(()=>{var e=window.matchMedia("(prefers-color-scheme: dark)").matches,t=localStorage.getItem("darkSwitch")!==null&&localStorage.getItem("darkSwitch")==="dark",n=localStorage.getItem("darkSwitch")!==null&&localStorage.getItem("darkSwitch")==="light";n&&(e=!1),t||e?document.documentElement.setAttribute("color-theme","dark"):document.documentElement.setAttribute("color-theme","light")})()</script><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@docsearch/css@3 media=print onload='this.media="all"'><link rel=preconnect href=https://9UXKYX61NK-dsn.algolia.net crossorigin data-proofer-ignore><link href="https://docs.crossplane.io/scss/docs.0346bfd4a8aeace526724de64ddada78a0e5122b3b0c83b1021770d6ddef1160.css" rel=stylesheet><link rel=apple-touch-icon sizes=180x180 href=/apple-touch-icon.png><link rel=icon type=image/png sizes=32x32 href=/favicon-32x32.png><link rel=icon type=image/png sizes=192x192 href=/android-chrome-192x192.png><link rel=icon type=image/png sizes=16x16 href=/favicon-16x16.png><link rel=manifest href=/site.webmanifest><link rel=mask-icon href=/safari-pinned-tab.svg color=#f87c44><meta name=apple-mobile-web-app-title content="Crossplane Docs"><meta name=application-name content="Crossplane Docs"><meta name=msapplication-TileColor content="#333f5b"><meta name=theme-color content="#ffffff"><meta property="og:title" content="Crossplane Docs · v1.16 · Write a Composition Function in Go"><meta property="og:description" content="Composition functions (or just functions, for short) are custom programs that template Crossplane resources. Crossplane calls composition functions to determine what resources it should create when …"></head><body><svg xmlns="http://www.w3.org/2000/svg" style="display:none"><symbol id="check2" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5.0 010 .708l-7 7a.5.5.0 01-.708.0l-3.5-3.5a.5.5.0 11.708-.708L6.5 10.293l6.646-6.647a.5.5.0 01.708.0z"/></symbol><symbol id="x" viewBox="0 0 16 16"><path d="M2.146 2.854a.5.5.0 11.708-.708L8 7.293l5.146-5.147a.5.5.0 01.708.708L8.707 8l5.147 5.146a.5.5.0 01-.708.708L8 8.707l-5.146 5.147a.5.5.0 01-.708-.708L7.293 8 2.146 2.854z"/></symbol><symbol id="chevron-expand" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M3.646 9.146a.5.5.0 01.708.0L8 12.793l3.646-3.647a.5.5.0 01.708.708l-4 4a.5.5.0 01-.708.0l-4-4a.5.5.0 010-.708zm0-2.292a.5.5.0 00.708.0L8 3.207l3.646 3.647a.5.5.0 00.708-.708l-4-4a.5.5.0 00-.708.0l-4 4a.5.5.0 000 .708z"/></symbol><symbol id="clipboard" viewBox="0 0 16 16"><path d="M4 1.5H3a2 2 0 00-2 2V14a2 2 0 002 2h10a2 2 0 002-2V3.5a2 2 0 00-2-2h-1v1h1a1 1 0 011 1V14a1 1 0 01-1 1H3a1 1 0 01-1-1V3.5a1 1 0 011-1h1v-1z"/><path d="M9.5 1a.5.5.0 01.5.5v1a.5.5.0 01-.5.5h-3A.5.5.0 016 2.5v-1a.5.5.0 01.5-.5h3zm-3-1A1.5 1.5.0 005 1.5v1A1.5 1.5.0 006.5 4h3A1.5 1.5.0 0011 2.5v-1A1.5 1.5.0 009.5.0h-3z"/></symbol><symbol id="plus" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 2a.5.5.0 01.5.5v5h5a.5.5.0 010 1h-5v5a.5.5.0 01-1 0v-5h-5a.5.5.0 010-1h5v-5A.5.5.0 018 2z"/></symbol><symbol id="three-dots" viewBox="0 0 16 16"><path d="M3 9.5a1.5 1.5.0 110-3 1.5 1.5.0 010 3zm5 0a1.5 1.5.0 110-3 1.5 1.5.0 010 3zm5 0a1.5 1.5.0 110-3 1.5 1.5.0 010 3z"/></symbol><symbol id="info" viewBox="0 0 16 16"><path d="M8 15A7 7 0 118 1a7 7 0 010 14zm0 1A8 8 0 108 0a8 8 0 000 16z"/><path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545.0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275.0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 11-2 0 1 1 0 012 0z"/></symbol><symbol id="check" viewBox="0 0 16 16"><path d="M8 15A7 7 0 118 1a7 7 0 010 14zm0 1A8 8 0 108 0a8 8 0 000 16z"/><path d="M10.97 4.97a.235.235.0 00-.02.022L7.477 9.417 5.384 7.323a.75.75.0 00-1.06 1.06L6.97 11.03a.75.75.0 001.079-.02l3.992-4.99A.75.75.0 0010.97 4.97z"/></symbol><symbol id="exclamation" viewBox="0 0 16 16"><path d="M8 15A7 7 0 118 1a7 7 0 010 14zm0 1A8 8 0 108 0a8 8 0 000 16z"/><path d="M7.002 11a1 1 0 112 0 1 1 0 01-2 0zM7.1 4.995a.905.905.0 111.8.0l-.35 3.507a.552.552.0 01-1.1.0L7.1 4.995z"/></symbol><symbol id="x-circle" viewBox="0 0 16 16"><path d="M8 15A7 7 0 118 1a7 7 0 010 14zm0 1A8 8 0 108 0a8 8 0 000 16z"/><path d="M4.646 4.646a.5.5.0 01.708.0L8 7.293l2.646-2.647a.5.5.0 01.708.708L8.707 8l2.647 2.646a.5.5.0 01-.708.708L8 8.707l-2.646 2.647a.5.5.0 01-.708-.708L7.293 8 4.646 5.354a.5.5.0 010-.708z"/></symbol><symbol id="fire" viewBox="0 0 16 16"><path d="M8 16c3.314.0 6-2 6-5.5.0-1.5-.5-4-2.5-6 .25 1.5-1.25 2-1.25 2C11 4 9 .5 6 0c.357 2 .5 4-2 6-1.25 1-2 2.729-2 4.5C2 14 4.686 16 8 16zm0-1c-1.657.0-3-1-3-2.75.0-.75.25-2 1.25-3C6.125 10 7 10.5 7 10.5c-.375-1.25.5-3.25 2-3.5-.179 1-.25 2 1 3 .625.5 1 1.364 1 2.25C11 14 9.657 15 8 15z"/></symbol><symbol id="search" viewBox="0 0 16 16"><path d="M11.742 10.344a6.5 6.5.0 10-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 001.415-1.414l-3.85-3.85a1.007 1.007.0 00-.115-.1zM12 6.5a5.5 5.5.0 11-11 0 5.5 5.5.0 0111 0z"/></symbol><symbol id="clipboard-check" viewBox="0 0 16 16"><path d="M6.5.0A1.5 1.5.0 005 1.5v1A1.5 1.5.0 006.5 4h3A1.5 1.5.0 0011 2.5v-1A1.5 1.5.0 009.5.0h-3zm3 1a.5.5.0 01.5.5v1a.5.5.0 01-.5.5h-3A.5.5.0 016 2.5v-1a.5.5.0 01.5-.5h3z"/><path d="M4 1.5H3a2 2 0 00-2 2V14a2 2 0 002 2h10a2 2 0 002-2V3.5a2 2 0 00-2-2h-1v1A2.5 2.5.0 019.5 5h-3A2.5 2.5.0 014 2.5v-1zm6.854 7.354-3 3a.5.5.0 01-.708.0l-1.5-1.5a.5.5.0 01.708-.708L7.5 10.793l2.646-2.647a.5.5.0 01.708.708z"/></symbol><symbol id="pencil-square" viewBox="0 0 16 16"><path d="M15.502 1.94a.5.5.0 010 .706L14.459 3.69l-2-2L13.502.646a.5.5.0 01.707.0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5.0 00-.121.196l-.805 2.414a.25.25.0 00.316.316l2.414-.805a.5.5.0 00.196-.12l6.813-6.814z"/><path fill-rule="evenodd" d="M1 13.5A1.5 1.5.0 002.5 15h11a1.5 1.5.0 001.5-1.5v-6a.5.5.0 00-1 0v6a.5.5.0 01-.5.5h-11a.5.5.0 01-.5-.5v-11a.5.5.0 01.5-.5H9a.5.5.0 000-1H2.5A1.5 1.5.0 001 2.5v11z"/></symbol><symbol id="github" viewBox="0 0 16 16"><path d="M8 0C3.58.0.0 3.58.0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38.0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95.0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12.0.0.67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15.0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48.0 1.07-.01 1.93-.01 2.2.0.21.15.46.55.38A8.012 8.012.0 0016 8c0-4.42-3.58-8-8-8z"/></symbol><symbol id="box-arrow-up-right" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8.636 3.5a.5.5.0 00-.5-.5H1.5A1.5 1.5.0 000 4.5v10A1.5 1.5.0 001.5 16h10a1.5 1.5.0 001.5-1.5V7.864a.5.5.0 00-1 0V14.5a.5.5.0 01-.5.5h-10a.5.5.0 01-.5-.5v-10a.5.5.0 01.5-.5h6.636a.5.5.0 00.5-.5z"/><path fill-rule="evenodd" d="M16 .5a.5.5.0 00-.5-.5h-5a.5.5.0 000 1h3.793L6.146 9.146a.5.5.0 10.708.708L15 1.707V5.5a.5.5.0 001 0v-5z"/></symbol></svg><header class="navbar docs-navbar navbar-expand-lg py-0 align-items-center"><div class=docs-left-toggle><button class=navbar-toggler type=button data-bs-toggle=offcanvas data-bs-target=#bdSidebar aria-controls=bdSidebar aria-label="Toggle docs content"><svg xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="1.5rem" fill="currentcolor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M2.5 11.5A.5.5.0 013 11h10a.5.5.0 010 1H3a.5.5.0 01-.5-.5zm0-4A.5.5.0 013 7h10a.5.5.0 010 1H3a.5.5.0 01-.5-.5zm0-4A.5.5.0 013 3h10a.5.5.0 010 1H3a.5.5.0 01-.5-.5z"/></svg> <span class="d-none fs-6 pe-1">Browse</span></button></div><div class="docs-right-toggle order-3"><button class=navbar-toggler type=button data-bs-toggle=offcanvas data-bs-target=#offcanvas aria-controls=offcanvas aria-label="Toggle Crossplane navigation"><svg class="bi white" aria-hidden="true"><use xlink:href="#three-dots"/></svg></button></div><div class=navbar-brand><a href=https://www.crossplane.io aria-label=Crossplane><img src=/img/crossplane-logo.svg alt="Crossplane logo" srcset="/img/crossplane-logo.svg 1x, /img/crossplane-logo.svg 2x" width=152px decoding=async data-nimg=future loading=lazy></a></div><div class="w-100 offcanvas-lg offcanvas-end" tabindex=-1 id=offcanvas aria-labelledby=offcanvasLabel><div class="offcanvas-body p-0"><div class="offcanvas-header p-0"><div class=navbar-brand><a href=https://www.crossplane.io aria-label=Crossplane><img src=/img/crossplane-logo.svg alt="Crossplane logo" srcset="/img/crossplane-logo.svg 1x, /img/crossplane-logo.svg 2x" width=152px decoding=async data-nimg=future loading=lazy></a></div><button type=button class="btn-close btn-close-white" data-bs-dismiss=offcanvas aria-label=Close data-bs-target=#offcanvas></button></div><div class="navbar-center-links collapse navbar-collapse justify-content-evenly show"><ul class="navbar-nav align-items-center"><li class=nav-item><a class=navbar-link href=https://www.crossplane.io/why-control-planes>Why Control Planes?</a></li><li class=nav-item><a class=navbar-link aria-current=page href=https://docs.crossplane.io/>Documentation</a></li><li class=nav-item><a class=navbar-link href=https://www.crossplane.io/community>Community</a></li><li class=nav-item><a class=navbar-link href=https://blog.crossplane.io/>Blog</a></li></ul></div><div class="navbar-icons flex-shrink-1 show"><ul class=navbar-nav><li class="nav-item col-xs p-2"><a class=navbar-link href=https://github.com/crossplane title="Crossplane Github Repository" target=_blank rel=noopener><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentcolor" class="icon-github" viewBox="0 0 16 16"><path d="M8 0C3.58.0.0 3.58.0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38.0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95.0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12.0.0.67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15.0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48.0 1.07-.01 1.93-.01 2.2.0.21.15.46.55.38A8.012 8.012.0 0016 8c0-4.42-3.58-8-8-8z"/></svg><span class=icon-label>Crossplane GitHub</span></a></li><li class="nav-item col-xs p-2"><div id=slack><a class=navbar-link href=https://slack.crossplane.io title="Join the Crossplane Slack" target=_blank rel=noopener><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentcolor" class="icon-slack" viewBox="0 0 16 16"><path d="M3.362 10.11c0 .926-.756 1.681-1.681 1.681S0 11.036.0 10.111C0 9.186.756 8.43 1.68 8.43h1.682v1.68zm.846.0c0-.924.756-1.68 1.681-1.68s1.681.756 1.681 1.68v4.21c0 .924-.756 1.68-1.68 1.68a1.685 1.685.0 01-1.682-1.68v-4.21zM5.89 3.362c-.926.0-1.682-.756-1.682-1.681S4.964.0 5.89.0s1.68.756 1.68 1.68v1.682H5.89zm0 .846c.924.0 1.68.756 1.68 1.681S6.814 7.57 5.89 7.57H1.68C.757 7.57.0 6.814.0 5.89c0-.926.756-1.682 1.68-1.682h4.21zm6.749 1.682c0-.926.755-1.682 1.68-1.682.925.0 1.681.756 1.681 1.681s-.756 1.681-1.68 1.681h-1.681V5.89zm-.848.0c0 .924-.755 1.68-1.68 1.68A1.685 1.685.0 018.43 5.89V1.68C8.43.757 9.186.0 10.11.0c.926.0 1.681.756 1.681 1.68v4.21zm-1.681 6.748c.926.0 1.682.756 1.682 1.681S11.036 16 10.11 16s-1.681-.756-1.681-1.68v-1.682h1.68zm0-.847c-.924.0-1.68-.755-1.68-1.68.0-.925.756-1.681 1.68-1.681h4.21c.924.0 1.68.756 1.68 1.68.0.926-.756 1.681-1.68 1.681h-4.21z"/></svg><span class=icon-label>Crossplane Slack</span></a></div></li><li class="nav-item col-x p-2"><div class="vr d-lg-flex mx-lg-2 text-white"></div></li><li class="nav-item col-xs p-2"><div class="form-check form-switch color-switcher"><input class="d-flex form-check-input" type=checkbox id=darkSwitch> <label class="d-flex navbar-link form-check-label" for=darkSwitch>Dark Mode</label></div></li></ul></div></div></div></header><div class="bd-layout docs-container" data-bs-spy=scroll data-bs-target=#TableOfContents data-bs-threshold=0,1 data-bs-root-margin="0% 0% -75%"><aside class=bd-sidebar><div class="offcanvas-lg offcanvas-start bd-sidebar-container" tabindex=-1 id=bdSidebar aria-labelledby=bdSidebarOffcanvasLabel><div class="offcanvas-header pb-4 border-bottom"><div class="d-flex offcanvas-title fw-bold" id=bdNavbarOffcanvasLabel>Crossplane Documentation - v1.16</div><div class=d-flex><button type=button class="btn-close bi align-self-center p-0" data-bs-dismiss=offcanvas aria-label=Close data-bs-target=#bdSidebar></button></div></div><div class=offcanvas-body><div class="container-fluid p-0"><div class="search-container d-flex row pt-3 ps-4 docsearch opacity-50" data-bs-target=#bdSidebar data-bs-dismiss=offcanvas aria-label="Docs navigation"><div class=p-0 id=docSearch></div></div><nav class="bd-links-nav w-100" aria-label="Docs navigation"><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100"><a class="d-flex w-100 border-0" href=https://docs.crossplane.io/v1.16/>Overview</a></div></div><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100"><a class="d-flex w-100 border-0" href=https://docs.crossplane.io/v1.16/getting-started/>Getting Started</a><div class="d-flex flex-shrink-1 sidebar-control-container align-self-center"><input type=checkbox class="d-flex sidebar-checkbox" aria-label="Close or Expand Getting Started Section"> <label for=collapse-ddb170dc class="sidebar-label collapsed" data-bs-toggle=collapse data-bs-target=#collapse-ddb170dc aria-expanded=false aria-label="Close or Expand Getting Started Section"><svg class="flex bi sidebar-icon plus"><use xlink:href="#plus"/></svg><svg class="flex bi sidebar-icon x"><use xlink:href="#x"/></svg></label></div></div><div class="container flex-row collapse" id=collapse-ddb170dc><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/getting-started/introduction/>Crossplane Introduction</a></div></div><div class="container flex-row collapse" id=collapse-ddb170dc><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/getting-started/provider-aws/>AWS Quickstart</a></div></div><div class="container flex-row collapse" id=collapse-ddb170dc><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/getting-started/provider-azure/>Azure Quickstart</a></div></div><div class="container flex-row collapse" id=collapse-ddb170dc><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/getting-started/provider-gcp/>GCP Quickstart</a></div></div></div><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100"><a class="d-flex w-100 border-0" href=https://docs.crossplane.io/v1.16/software/>Install, Upgrade and Uninstall</a><div class="d-flex flex-shrink-1 sidebar-control-container align-self-center"><input type=checkbox class="d-flex sidebar-checkbox" aria-label="Close or Expand Install, Upgrade and Uninstall Section"> <label for=collapse-9f2b1e08 class="sidebar-label collapsed" data-bs-toggle=collapse data-bs-target=#collapse-9f2b1e08 aria-expanded=false aria-label="Close or Expand Install, Upgrade and Uninstall Section"><svg class="flex bi sidebar-icon plus"><use xlink:href="#plus"/></svg><svg class="flex bi sidebar-icon x"><use xlink:href="#x"/></svg></label></div></div><div class="container flex-row collapse" id=collapse-9f2b1e08><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/software/install/>Install Crossplane</a></div></div><div class="container flex-row collapse" id=collapse-9f2b1e08><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/software/upgrade/>Upgrade Crossplane</a></div></div><div class="container flex-row collapse" id=collapse-9f2b1e08><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/software/uninstall/>Uninstall Crossplane</a></div></div></div><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100"><a class="d-flex w-100 border-0" href=https://docs.crossplane.io/v1.16/concepts/>Concepts</a><div class="d-flex flex-shrink-1 sidebar-control-container align-self-center"><input type=checkbox class="d-flex sidebar-checkbox" aria-label="Close or Expand Concepts Section"> <label for=collapse-9e31ed45 class="sidebar-label collapsed" data-bs-toggle=collapse data-bs-target=#collapse-9e31ed45 aria-expanded=false aria-label="Close or Expand Concepts Section"><svg class="flex bi sidebar-icon plus"><use xlink:href="#plus"/></svg><svg class="flex bi sidebar-icon x"><use xlink:href="#x"/></svg></label></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/pods/>Crossplane Pods</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/providers/>Providers</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/managed-resources/>Managed Resources</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/compositions/>Compositions</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/composition-revisions/>Composition Revisions</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/composite-resource-definitions/>Composite Resource Definitions</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/composite-resources/>Composite Resources</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/claims/>Claims</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/patch-and-transform/>Patch and Transforms</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/environment-configs/>Environment Configurations</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/composition-functions/>Composition Functions</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/usages/>Usages</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/connection-details/>Connection Details</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/packages/>Configuration Packages</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/server-side-apply/>Server-Side Apply</a></div></div><div class="container flex-row collapse" id=collapse-9e31ed45><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/concepts/image-configs/>Image Configs</a></div></div></div><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100 active-parent"><a class="d-flex w-100 border-0" href=https://docs.crossplane.io/v1.16/guides/>Guides</a><div class="d-flex flex-shrink-1 sidebar-control-container align-self-center"><input type=checkbox class="d-flex sidebar-checkbox" checked aria-label="Close or Expand Guides Section"> <label for=collapse-c8ab9da3 class=sidebar-label data-bs-toggle=collapse data-bs-target=#collapse-c8ab9da3 aria-expanded=false aria-label="Close or Expand Guides Section"><svg class="flex bi sidebar-icon plus"><use xlink:href="#plus"/></svg><svg class="flex bi sidebar-icon x"><use xlink:href="#x"/></svg></label></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/disaster-recovery/>Disaster Recovery with Crossplane</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex active" href=https://docs.crossplane.io/v1.16/guides/write-a-composition-function-in-go/>Write a Composition Function in Go</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/write-a-composition-function-in-python/>Write a Composition Function in Python</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/import-existing-resources/>Import Existing Resources</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/vault-as-secret-store/>Vault as an External Secret Store</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/vault-injection/>Vault Credential Injection</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/multi-tenant/>Multi-Tenant Crossplane</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/crossplane-with-argo-cd/>Configuring Crossplane with Argo CD</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/self-signed-ca-certs/>Self-Signed CA Certs</a></div></div><div class="container flex-row collapse show" id=collapse-c8ab9da3><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/guides/troubleshoot-crossplane/>Troubleshoot Crossplane</a></div></div></div><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100"><a class="d-flex w-100 border-0" href=https://docs.crossplane.io/v1.16/cli/>CLI Reference</a><div class="d-flex flex-shrink-1 sidebar-control-container align-self-center"><input type=checkbox class="d-flex sidebar-checkbox" aria-label="Close or Expand CLI Reference Section"> <label for=collapse-2f1c64f4 class="sidebar-label collapsed" data-bs-toggle=collapse data-bs-target=#collapse-2f1c64f4 aria-expanded=false aria-label="Close or Expand CLI Reference Section"><svg class="flex bi sidebar-icon plus"><use xlink:href="#plus"/></svg><svg class="flex bi sidebar-icon x"><use xlink:href="#x"/></svg></label></div></div><div class="container flex-row collapse" id=collapse-2f1c64f4><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/cli/command-reference/>Command Reference</a></div></div></div><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100"><a class="d-flex w-100 border-0" href=https://docs.crossplane.io/v1.16/api/>API Reference</a><div class="d-flex flex-shrink-1 sidebar-control-container align-self-center"><input type=checkbox class="d-flex sidebar-checkbox" aria-label="Close or Expand API Reference Section"> <label for=collapse-569451c8 class="sidebar-label collapsed" data-bs-toggle=collapse data-bs-target=#collapse-569451c8 aria-expanded=false aria-label="Close or Expand API Reference Section"><svg class="flex bi sidebar-icon plus"><use xlink:href="#plus"/></svg><svg class="flex bi sidebar-icon x"><use xlink:href="#x"/></svg></label></div></div></div><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100"><a class="d-flex w-100 border-0" href=https://docs.crossplane.io/v1.16/learn/>Learn More</a><div class="d-flex flex-shrink-1 sidebar-control-container align-self-center"><input type=checkbox class="d-flex sidebar-checkbox" aria-label="Close or Expand Learn More Section"> <label for=collapse-47924500 class="sidebar-label collapsed" data-bs-toggle=collapse data-bs-target=#collapse-47924500 aria-expanded=false aria-label="Close or Expand Learn More Section"><svg class="flex bi sidebar-icon plus"><use xlink:href="#plus"/></svg><svg class="flex bi sidebar-icon x"><use xlink:href="#x"/></svg></label></div></div><div class="container flex-row collapse" id=collapse-47924500><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/learn/release-cycle/>Release Cycle</a></div></div><div class="container flex-row collapse" id=collapse-47924500><div class="d-flex flex-column"><a class="bd-links d-flex" href=https://docs.crossplane.io/v1.16/learn/feature-lifecycle/>Feature Lifecycle</a></div></div></div><div class="section-container container pe-0 pt-1"><div class=nav-container><a href=https://docs.crossplane.io/contribute/ class="d-inline-flex align-items-center">Contributing Guide</a></div></div><div class="section-container container pe-0 pt-1"><div class="container nav-container pe-0 d-flex w-100"><a class="d-flex w-100 border-0" href="https://github.com/orgs/crossplane/projects/20/views/9?pane=info" target=_blank>Crossplane Roadmap</a><div class="d-flex flex-shrink-1 sidebar-control-container align-self-center"><a href="https://github.com/orgs/crossplane/projects/20/views/9?pane=info"><svg class="flex bi"><use xlink:href="#box-arrow-up-right"/></svg></a></div></div></div></nav></div></div></aside><main class="bd-main order-1"><div class="bd-intro pt-2 ps-lg-2"><div class="d-md-flex flex-md-row-reverse align-items-center justify-content-between"><div class="mb-3 mb-md-0 d-flex"><div class="dropdown float-end bd-dropdown"><a class="btn btn-outline-secondary dropdown-toggle bd-dropdown-item text-reset" href=# role=button id=dropdownMenuLink data-bs-toggle=dropdown aria-haspopup=true aria-expanded=false>v1.16</a><div class="dropdown-menu bd-border-color bd-dropdown" aria-labelledby=dropdownMenuLink><a class="dropdown-item bd-dropdown-item" href=https://docs.crossplane.io/master/guides/write-a-composition-function-in-go/>master</a> <a class="dropdown-item bd-dropdown-item" href=https://docs.crossplane.io/v1.18/guides/write-a-composition-function-in-go/>v1.18<div class="badge rounded-pill latest">Latest</div></a><a class="dropdown-item bd-dropdown-item" href=https://docs.crossplane.io/v1.17/guides/write-a-composition-function-in-go/>v1.17</a> <a class="dropdown-item bd-dropdown-item active" aria-current=true href=https://docs.crossplane.io/v1.16/guides/write-a-composition-function-in-go/>v1.16</a></div></div></div><h1 class="bd-title mb-0" id=content>Write a Composition Function in Go</h1></div><div class="bd-callout bd-callout-warning d-flex flex-column w-100"><div class="d-flex bd-title fs-6 fw-bold border-bottom border-danger"><div class="d-flex pe-3 align-self-center"><svg class="bi flex-shrink-0" role="img" aria-label="Warning:"><use xlink:href="#fire"/></svg></div><div class=d-flex>This is a beta feature.</div></div><div class="bd-content mt-3"><p>This feature was introduced in v1.11.<br>This feature graduated to beta status in v1.14.<br><br>For more information read the <a href=https://docs.crossplane.io/v1.16/learn/feature-lifecycle/>Crossplane feature lifecycle</a>.</p></div></div></div><div class="bd-toc mt-3 mb-5 my-lg-0 ps-xl-3 mb-lg-5"><button class="btn btn-link p-md-0 mb-2 mb-md-0 text-decoration-none bd-toc-toggle d-md-none" type=button data-bs-toggle=collapse data-bs-target=#tocContents aria-expanded=false aria-controls=tocContents> On this page<svg class="bi d-md-none ms-2" aria-hidden="true"><use xlink:href="#chevron-expand"/></svg></button> <strong class="d-none d-md-block h6 my-2">On this page</strong><hr class="d-none d-md-block my-2"><div class="collapse bd-toc-collapse" id=tocContents><nav id=TableOfContents><ul class=nav><li class=nav-item><a class=nav-link href=#understand-the-steps>Understand the steps</a></li><li class=nav-item><a class=nav-link href=#install-the-tools-you-need-to-write-the-function>Install the tools you need to write the function</a></li><li class=nav-item><a class=nav-link href=#initialize-the-function-from-a-template>Initialize the function from a template</a></li><li class=nav-item><a class=nav-link href=#edit-the-template-to-add-the-functions-logic>Edit the template to add the function’s logic</a></li><li class=nav-item><a class=nav-link href=#test-the-function-end-to-end>Test the function end-to-end</a></li><li class=nav-item><a class=nav-link href=#build-and-push-the-function-to-a-package-registry>Build and push the function to a package registry</a></li></ul></li></ul></nav><nav class=pt-3><div class=pb-2><svg class="bi" width="1em" height="1em"><use xlink:href="#pencil-square"/></svg><span class=ps-1><a target=_blank href="https://github.com/crossplane/docs/issues/new?title=[Web%20Bug]%20-%20Write%20a%20Composition%20Function%20in%20Go&body=%3c!--%20What%27s%20the%20problem?%20--%3e%0a%0a%0aURL:%20https://docs.crossplane.io/v1.16/guides/write-a-composition-function-in-go/">Report a problem</a></span></div><div><svg class="bi" width="1em" height="1em"><use xlink:href="#github"/></svg><span class=ps-1><a href=https://github.com/crossplane/docs/tree/master/content/v1.16/guides/write-a-composition-function-in-go.md>View page source</a></span></div></div></nav></div><div class="bd-content ps-lg-2 DocSearch-content"><div class="bd-callout bd-callout-info d-flex flex-column w-100"><div class="d-flex bd-title fs-6 fw-bold border-bottom border-info"><div class="d-flex pe-3 align-self-center"><svg class="bi flex-shrink-0" role="img" aria-label="Info:"><use xlink:href="#info"/></svg></div><div class=d-flex>This document is for an older version of Crossplane.</div></div><div class=mt-3><p>This document applies to Crossplane version v1.16 and not to the latest release v1.18.</p></div></div><p>Composition functions (or just functions, for short) are custom programs that template Crossplane resources. Crossplane calls composition functions to determine what resources it should create when you create a composite resource (XR). Read the <a href=https://docs.crossplane.io/v1.16/concepts/composition-functions/>concepts</a> page to learn more about composition functions.</p><p>You can write a function to template resources using a general purpose programming language. Using a general purpose programming language allows a function to use advanced logic to template resources, like loops and conditionals. This guide explains how to write a composition function in <a href=https://go.dev>Go</a>.</p><div class="admonition important d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="important:"><use xlink:href="#exclamation"/></svg><span class=ps-1>Important</span></div><div class=admonition-content>It helps to be familiar with <a href=https://docs.crossplane.io/v1.16/concepts/composition-functions/#how-composition-functions-work>how composition functions work</a> before following this guide.</div></div><h2 id=understand-the-steps>Understand the steps <a class=anchor-link id=understand-the-steps href=#understand-the-steps aria-label="Link to this section: Understand the steps"></a></h2><p>This guide covers writing a composition function for an <code><highlight-term id=1731573034470741952 data-label=xr data-line=2>XBuckets</highlight-term></code> composite resource (XR).</p><div class=highlight label=xr><pre tabindex=0 class=chroma><code class=language-yaml data-lang=yaml><span class=line><span class=ln id=hl-0-1><a class=lnlinks href=#hl-0-1> 1</a></span><span class=cl><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>example.crossplane.io/v1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-2><a class=lnlinks href=#hl-0-2> 2</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>XBuckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-3><a class=lnlinks href=#hl-0-3> 3</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-4><a class=lnlinks href=#hl-0-4> 4</a></span><span class=cl><span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-5><a class=lnlinks href=#hl-0-5> 5</a></span><span class=cl><span class=w></span><span class=nt>spec</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-6><a class=lnlinks href=#hl-0-6> 6</a></span><span class=cl><span class=w> </span><span class=nt>region</span><span class=p>:</span><span class=w> </span><span class=l>us-east-2</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-7><a class=lnlinks href=#hl-0-7> 7</a></span><span class=cl><span class=w> </span><span class=nt>names</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-8><a class=lnlinks href=#hl-0-8> 8</a></span><span class=cl><span class=w> </span>- <span class=l>crossplane-functions-example-a</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-9><a class=lnlinks href=#hl-0-9> 9</a></span><span class=cl><span class=w> </span>- <span class=l>crossplane-functions-example-b</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-10><a class=lnlinks href=#hl-0-10>10</a></span><span class=cl><span class=w> </span>- <span class=l>crossplane-functions-example-c</span><span class=w> </span></span></span></code></pre></div><p>An <code>XBuckets</code> XR has a region and an array of bucket names. The function will create an Amazon Web Services (AWS) S3 bucket for each entry in the names array.</p><p>To write a function in Go:</p><ol><li><a href=#install-the-tools-you-need-to-write-the-function>Install the tools you need to write the function</a></li><li><a href=#initialize-the-function-from-a-template>Initialize the function from a template</a></li><li><a href=#edit-the-template-to-add-the-functions-logic>Edit the template to add the function’s logic</a></li><li><a href=#test-the-function-end-to-end>Test the function end-to-end</a></li><li><a href=#build-and-push-the-function-to-a-package-registry>Build and push the function to a package repository</a></li></ol><p>This guide covers each of these steps in detail.</p><h2 id=install-the-tools-you-need-to-write-the-function>Install the tools you need to write the function <a class=anchor-link id=install-the-tools-you-need-to-write-the-function href=#install-the-tools-you-need-to-write-the-function aria-label="Link to this section: Install the tools you need to write the function"></a></h2><p>To write a function in Go you need:</p><ul><li><a href=https://go.dev/dl/>Go</a> v1.21 or newer. The guide uses Go v1.21.</li><li><a href=https://docs.docker.com/engine/>Docker Engine</a>. This guide uses Engine v24.</li><li>The <a href=https://docs.crossplane.io/v1.16/cli/>Crossplane CLI</a> v1.14 or newer. This guide uses Crossplane CLI v1.14.</li></ul><div class="admonition note d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="note:"><use xlink:href="#info"/></svg><span class=ps-1>Note</span></div><div class=admonition-content>You don’t need access to a Kubernetes cluster or a Crossplane control plane to build or test a composition function.</div></div><h2 id=initialize-the-function-from-a-template>Initialize the function from a template <a class=anchor-link id=initialize-the-function-from-a-template href=#initialize-the-function-from-a-template aria-label="Link to this section: Initialize the function from a template"></a></h2><p>Use the <code>crossplane beta xpkg init</code> command to initialize a new function. When you run this command it initializes your function using <a href=https://github.com/crossplane/function-template-go>a GitHub repository</a> as a template.</p><div class=highlight copy-lines=1><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-1-1><a class=lnlinks href=#hl-1-1>1</a></span><span class=cl>crossplane beta xpkg init <span class=k>function</span>-xbuckets <span class=k>function</span>-template-go -d <span class=k>function</span>-xbuckets </span></span><span class=line><span class=ln id=hl-1-2><a class=lnlinks href=#hl-1-2>2</a></span><span class=cl>Initialized package <span class=s2>"function-xbuckets"</span> in directory <span class=s2>"/home/negz/control/negz/function-xbuckets"</span> from https://github.com/crossplane/function-template-go/tree/91a1a5eed21964ff98966d72cc6db6f089ad63f4 <span class=o>(</span>main<span class=o>)</span> </span></span></code></pre></div><p>The <code>crossplane beta init xpkg</code> command creates a directory named <code>function-xbuckets</code>. When you run the command the new directory should look like this:</p><div class=highlight copy-lines=1><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-2-1><a class=lnlinks href=#hl-2-1>1</a></span><span class=cl>ls <span class=k>function</span>-xbuckets </span></span><span class=line><span class=ln id=hl-2-2><a class=lnlinks href=#hl-2-2>2</a></span><span class=cl>Dockerfile fn.go fn_test.go go.mod go.sum input/ LICENSE main.go package/ README.md renovate.json </span></span></code></pre></div><p>The <code>fn.go</code> file is where you add the function’s code. It’s useful to know about some other files in the template:</p><ul><li><code>main.go</code> runs the function. You don’t need to edit <code>main.go</code>.</li><li><code>Dockerfile</code> builds the function runtime. You don’t need to edit <code>Dockerfile</code>.</li><li>The <code>input</code> directory defines the function’s input type.</li><li>The <code>package</code> directory contains metadata used to build the function package.</li></ul><div class="admonition tip d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="tip:"><use xlink:href="#check"/></svg><span class=ps-1>Tip</span></div><div class=admonition-content><p>In v1.14 of the Crossplane CLI <code>crossplane beta xpkg init</code> just clones a template GitHub repository. A future CLI release will automate tasks like replacing the template name with the new function’s name. See Crossplane issue <a href=https://github.com/crossplane/crossplane/issues/4941>#4941</a> for details.</p></div></div><p>You must make some changes before you start adding code:</p><ul><li>Edit <code>package/crossplane.yaml</code> to change the package’s name.</li><li>Edit <code>go.mod</code> to change the Go module’s name.</li></ul><p>Name your package <code>function-xbuckets</code>.</p><p>The name of your module depends on where you want to keep your function code. If you push Go code to GitHub, you can use your GitHub username. For example <code>module github.com/negz/function-xbuckets</code>.</p><p>The function in this guide doesn’t use an input type. For this function you should delete the <code>input</code> and <code>package/input</code> directories.</p><p>The <code>input</code> directory defines a Go struct that a function can use to take input, using the <code>input</code> field from a Composition. The <a href=https://docs.crossplane.io/v1.16/concepts/composition-functions/>composition functions</a> documentation explains how to pass an input to a composition function.</p><p>The <code>package/input</code> directory contains an OpenAPI schema generated from the structs in the <code>input</code> directory.</p><div class="admonition tip d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="tip:"><use xlink:href="#check"/></svg><span class=ps-1>Tip</span></div><div class=admonition-content><p>If you’re writing a function that uses an input, edit the input to meet your function’s requirements.</p><p>Change the input’s kind and API group. Don’t use <code>Input</code> and <code>template.fn.crossplane.io</code>. Instead use something meaningful to your function.</p><p>When you edit files under the <code>input</code> directory you must update some generated files by running <code>go generate</code>. See <code>input/generate.go</code> for details.</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-0-1><a class=lnlinks href=#hl-0-1>1</a></span><span class=cl>go generate ./... </span></span></code></pre></div></div></div><h2 id=edit-the-template-to-add-the-functions-logic>Edit the template to add the function’s logic <a class=anchor-link id=edit-the-template-to-add-the-functions-logic href=#edit-the-template-to-add-the-functions-logic aria-label="Link to this section: Edit the template to add the function’s logic"></a></h2><p>You add your function’s logic to the <code><highlight-term id=1731573034471073272 data-label=hello-world data-line=1>RunFunction</highlight-term></code> method in <code>fn.go</code>. When you first open the file it contains a “hello world” function.</p><div class=highlight label=hello-world><pre tabindex=0 class=chroma><code class=language-go data-lang=go><span class=line><span class=ln id=hl-3-1><a class=lnlinks href=#hl-3-1> 1</a></span><span class=cl><span class=kd>func</span> <span class=p>(</span><span class=nx>f</span> <span class=o>*</span><span class=nx>Function</span><span class=p>)</span> <span class=nf>RunFunction</span><span class=p>(</span><span class=nx>_</span> <span class=nx>context</span><span class=p>.</span><span class=nx>Context</span><span class=p>,</span> <span class=nx>req</span> <span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionRequest</span><span class=p>)</span> <span class=p>(</span><span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionResponse</span><span class=p>,</span> <span class=kt>error</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-3-2><a class=lnlinks href=#hl-3-2> 2</a></span><span class=cl> <span class=nx>f</span><span class=p>.</span><span class=nx>log</span><span class=p>.</span><span class=nf>Info</span><span class=p>(</span><span class=s>"Running Function"</span><span class=p>,</span> <span class=s>"tag"</span><span class=p>,</span> <span class=nx>req</span><span class=p>.</span><span class=nf>GetMeta</span><span class=p>().</span><span class=nf>GetTag</span><span class=p>())</span> </span></span><span class=line><span class=ln id=hl-3-3><a class=lnlinks href=#hl-3-3> 3</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-3-4><a class=lnlinks href=#hl-3-4> 4</a></span><span class=cl> <span class=nx>rsp</span> <span class=o>:=</span> <span class=nx>response</span><span class=p>.</span><span class=nf>To</span><span class=p>(</span><span class=nx>req</span><span class=p>,</span> <span class=nx>response</span><span class=p>.</span><span class=nx>DefaultTTL</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-3-5><a class=lnlinks href=#hl-3-5> 5</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-3-6><a class=lnlinks href=#hl-3-6> 6</a></span><span class=cl> <span class=nx>in</span> <span class=o>:=</span> <span class=o>&</span><span class=nx>v1beta1</span><span class=p>.</span><span class=nx>Input</span><span class=p>{}</span> </span></span><span class=line><span class=ln id=hl-3-7><a class=lnlinks href=#hl-3-7> 7</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>request</span><span class=p>.</span><span class=nf>GetInput</span><span class=p>(</span><span class=nx>req</span><span class=p>,</span> <span class=nx>in</span><span class=p>);</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-3-8><a class=lnlinks href=#hl-3-8> 8</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot get Function input from %T"</span><span class=p>,</span> <span class=nx>req</span><span class=p>))</span> </span></span><span class=line><span class=ln id=hl-3-9><a class=lnlinks href=#hl-3-9> 9</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-3-10><a class=lnlinks href=#hl-3-10>10</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-3-11><a class=lnlinks href=#hl-3-11>11</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-3-12><a class=lnlinks href=#hl-3-12>12</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Normalf</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=s>"I was run with input %q"</span><span class=p>,</span> <span class=nx>in</span><span class=p>.</span><span class=nx>Example</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-3-13><a class=lnlinks href=#hl-3-13>13</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-3-14><a class=lnlinks href=#hl-3-14>14</a></span><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>All Go composition functions have a <code>RunFunction</code> method. Crossplane passes everything the function needs to run in a <code><highlight-term id=1731573034471100116 data-label=hello-world data-line=1>RunFunctionRequest</highlight-term></code> struct.</p><p>The function tells Crossplane what resources it should compose by returning a <code><highlight-term id=1731573034471122366 data-label=hello-world data-line=13>RunFunctionResponse</highlight-term></code> struct.</p><div class="admonition tip d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="tip:"><use xlink:href="#check"/></svg><span class=ps-1>Tip</span></div><div class=admonition-content>Crossplane generates the <code>RunFunctionRequest</code> and <code>RunFunctionResponse</code> structs using <a href=http://protobuf.dev>Protocol Buffers</a>. You can find detailed schemas for <code>RunFunctionRequest</code> and <code>RunFunctionResponse</code> in the <a href=https://buf.build/crossplane/crossplane/docs/main:apiextensions.fn.proto.v1beta1>Buf Schema Registry</a>.</div></div><p>Edit the <code>RunFunction</code> method to replace it with this code.</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-go data-lang=go><span class=line><span class=ln id=hl-4-1><a class=lnlinks href=#hl-4-1> 1</a></span><span class=cl><span class=kd>func</span> <span class=p>(</span><span class=nx>f</span> <span class=o>*</span><span class=nx>Function</span><span class=p>)</span> <span class=nf>RunFunction</span><span class=p>(</span><span class=nx>_</span> <span class=nx>context</span><span class=p>.</span><span class=nx>Context</span><span class=p>,</span> <span class=nx>req</span> <span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionRequest</span><span class=p>)</span> <span class=p>(</span><span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionResponse</span><span class=p>,</span> <span class=kt>error</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-4-2><a class=lnlinks href=#hl-4-2> 2</a></span><span class=cl> <span class=nx>rsp</span> <span class=o>:=</span> <span class=nx>response</span><span class=p>.</span><span class=nf>To</span><span class=p>(</span><span class=nx>req</span><span class=p>,</span> <span class=nx>response</span><span class=p>.</span><span class=nx>DefaultTTL</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-4-3><a class=lnlinks href=#hl-4-3> 3</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-4><a class=lnlinks href=#hl-4-4> 4</a></span><span class=cl> <span class=nx>xr</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>request</span><span class=p>.</span><span class=nf>GetObservedCompositeResource</span><span class=p>(</span><span class=nx>req</span><span class=p>)</span> </span></span><span class="line hl"><span class=ln id=hl-4-5><a class=lnlinks href=#hl-4-5> 5</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-6><a class=lnlinks href=#hl-4-6> 6</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot get observed composite resource from %T"</span><span class=p>,</span> <span class=nx>req</span><span class=p>))</span> </span></span><span class="line hl"><span class=ln id=hl-4-7><a class=lnlinks href=#hl-4-7> 7</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class="line hl"><span class=ln id=hl-4-8><a class=lnlinks href=#hl-4-8> 8</a></span><span class=cl> <span class=p>}</span> </span></span><span class="line hl"><span class=ln id=hl-4-9><a class=lnlinks href=#hl-4-9> 9</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-10><a class=lnlinks href=#hl-4-10>10</a></span><span class=cl> <span class=nx>region</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetString</span><span class=p>(</span><span class=s>"spec.region"</span><span class=p>)</span> </span></span><span class="line hl"><span class=ln id=hl-4-11><a class=lnlinks href=#hl-4-11>11</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-12><a class=lnlinks href=#hl-4-12>12</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot read spec.region field of %s"</span><span class=p>,</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetKind</span><span class=p>()))</span> </span></span><span class="line hl"><span class=ln id=hl-4-13><a class=lnlinks href=#hl-4-13>13</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class="line hl"><span class=ln id=hl-4-14><a class=lnlinks href=#hl-4-14>14</a></span><span class=cl> <span class=p>}</span> </span></span><span class="line hl"><span class=ln id=hl-4-15><a class=lnlinks href=#hl-4-15>15</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-16><a class=lnlinks href=#hl-4-16>16</a></span><span class=cl> <span class=nx>names</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetStringArray</span><span class=p>(</span><span class=s>"spec.names"</span><span class=p>)</span> </span></span><span class="line hl"><span class=ln id=hl-4-17><a class=lnlinks href=#hl-4-17>17</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-18><a class=lnlinks href=#hl-4-18>18</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot read spec.names field of %s"</span><span class=p>,</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetKind</span><span class=p>()))</span> </span></span><span class="line hl"><span class=ln id=hl-4-19><a class=lnlinks href=#hl-4-19>19</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class="line hl"><span class=ln id=hl-4-20><a class=lnlinks href=#hl-4-20>20</a></span><span class=cl> <span class=p>}</span> </span></span><span class="line hl"><span class=ln id=hl-4-21><a class=lnlinks href=#hl-4-21>21</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-22><a class=lnlinks href=#hl-4-22>22</a></span><span class=cl> <span class=nx>desired</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>request</span><span class=p>.</span><span class=nf>GetDesiredComposedResources</span><span class=p>(</span><span class=nx>req</span><span class=p>)</span> </span></span><span class="line hl"><span class=ln id=hl-4-23><a class=lnlinks href=#hl-4-23>23</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-24><a class=lnlinks href=#hl-4-24>24</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot get desired resources from %T"</span><span class=p>,</span> <span class=nx>req</span><span class=p>))</span> </span></span><span class="line hl"><span class=ln id=hl-4-25><a class=lnlinks href=#hl-4-25>25</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class="line hl"><span class=ln id=hl-4-26><a class=lnlinks href=#hl-4-26>26</a></span><span class=cl> <span class=p>}</span> </span></span><span class="line hl"><span class=ln id=hl-4-27><a class=lnlinks href=#hl-4-27>27</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-28><a class=lnlinks href=#hl-4-28>28</a></span><span class=cl> <span class=nx>_</span> <span class=p>=</span> <span class=nx>v1beta1</span><span class=p>.</span><span class=nf>AddToScheme</span><span class=p>(</span><span class=nx>composed</span><span class=p>.</span><span class=nx>Scheme</span><span class=p>)</span> </span></span><span class="line hl"><span class=ln id=hl-4-29><a class=lnlinks href=#hl-4-29>29</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-30><a class=lnlinks href=#hl-4-30>30</a></span><span class=cl> <span class=k>for</span> <span class=nx>_</span><span class=p>,</span> <span class=nx>name</span> <span class=o>:=</span> <span class=k>range</span> <span class=nx>names</span> <span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-31><a class=lnlinks href=#hl-4-31>31</a></span><span class=cl> <span class=nx>b</span> <span class=o>:=</span> <span class=o>&</span><span class=nx>v1beta1</span><span class=p>.</span><span class=nx>Bucket</span><span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-32><a class=lnlinks href=#hl-4-32>32</a></span><span class=cl> <span class=nx>ObjectMeta</span><span class=p>:</span> <span class=nx>metav1</span><span class=p>.</span><span class=nx>ObjectMeta</span><span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-33><a class=lnlinks href=#hl-4-33>33</a></span><span class=cl> <span class=nx>Annotations</span><span class=p>:</span> <span class=kd>map</span><span class=p>[</span><span class=kt>string</span><span class=p>]</span><span class=kt>string</span><span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-34><a class=lnlinks href=#hl-4-34>34</a></span><span class=cl> <span class=s>"crossplane.io/external-name"</span><span class=p>:</span> <span class=nx>name</span><span class=p>,</span> </span></span><span class="line hl"><span class=ln id=hl-4-35><a class=lnlinks href=#hl-4-35>35</a></span><span class=cl> <span class=p>},</span> </span></span><span class="line hl"><span class=ln id=hl-4-36><a class=lnlinks href=#hl-4-36>36</a></span><span class=cl> <span class=p>},</span> </span></span><span class="line hl"><span class=ln id=hl-4-37><a class=lnlinks href=#hl-4-37>37</a></span><span class=cl> <span class=nx>Spec</span><span class=p>:</span> <span class=nx>v1beta1</span><span class=p>.</span><span class=nx>BucketSpec</span><span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-38><a class=lnlinks href=#hl-4-38>38</a></span><span class=cl> <span class=nx>ForProvider</span><span class=p>:</span> <span class=nx>v1beta1</span><span class=p>.</span><span class=nx>BucketParameters</span><span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-39><a class=lnlinks href=#hl-4-39>39</a></span><span class=cl> <span class=nx>Region</span><span class=p>:</span> <span class=nx>ptr</span><span class=p>.</span><span class=nx>To</span><span class=p>[</span><span class=kt>string</span><span class=p>](</span><span class=nx>region</span><span class=p>),</span> </span></span><span class="line hl"><span class=ln id=hl-4-40><a class=lnlinks href=#hl-4-40>40</a></span><span class=cl> <span class=p>},</span> </span></span><span class="line hl"><span class=ln id=hl-4-41><a class=lnlinks href=#hl-4-41>41</a></span><span class=cl> <span class=p>},</span> </span></span><span class="line hl"><span class=ln id=hl-4-42><a class=lnlinks href=#hl-4-42>42</a></span><span class=cl> <span class=p>}</span> </span></span><span class="line hl"><span class=ln id=hl-4-43><a class=lnlinks href=#hl-4-43>43</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-44><a class=lnlinks href=#hl-4-44>44</a></span><span class=cl> <span class=nx>cd</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>composed</span><span class=p>.</span><span class=nf>From</span><span class=p>(</span><span class=nx>b</span><span class=p>)</span> </span></span><span class="line hl"><span class=ln id=hl-4-45><a class=lnlinks href=#hl-4-45>45</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-46><a class=lnlinks href=#hl-4-46>46</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot convert %T to %T"</span><span class=p>,</span> <span class=nx>b</span><span class=p>,</span> <span class=o>&</span><span class=nx>composed</span><span class=p>.</span><span class=nx>Unstructured</span><span class=p>{}))</span> </span></span><span class="line hl"><span class=ln id=hl-4-47><a class=lnlinks href=#hl-4-47>47</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class="line hl"><span class=ln id=hl-4-48><a class=lnlinks href=#hl-4-48>48</a></span><span class=cl> <span class=p>}</span> </span></span><span class="line hl"><span class=ln id=hl-4-49><a class=lnlinks href=#hl-4-49>49</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-50><a class=lnlinks href=#hl-4-50>50</a></span><span class=cl> <span class=nx>desired</span><span class=p>[</span><span class=nx>resource</span><span class=p>.</span><span class=nf>Name</span><span class=p>(</span><span class=s>"xbuckets-"</span><span class=o>+</span><span class=nx>name</span><span class=p>)]</span> <span class=p>=</span> <span class=o>&</span><span class=nx>resource</span><span class=p>.</span><span class=nx>DesiredComposed</span><span class=p>{</span><span class=nx>Resource</span><span class=p>:</span> <span class=nx>cd</span><span class=p>}</span> </span></span><span class="line hl"><span class=ln id=hl-4-51><a class=lnlinks href=#hl-4-51>51</a></span><span class=cl> <span class=p>}</span> </span></span><span class="line hl"><span class=ln id=hl-4-52><a class=lnlinks href=#hl-4-52>52</a></span><span class=cl> </span></span><span class="line hl"><span class=ln id=hl-4-53><a class=lnlinks href=#hl-4-53>53</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>response</span><span class=p>.</span><span class=nf>SetDesiredComposedResources</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>desired</span><span class=p>);</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class="line hl"><span class=ln id=hl-4-54><a class=lnlinks href=#hl-4-54>54</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot set desired composed resources in %T"</span><span class=p>,</span> <span class=nx>rsp</span><span class=p>))</span> </span></span><span class="line hl"><span class=ln id=hl-4-55><a class=lnlinks href=#hl-4-55>55</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class="line hl"><span class=ln id=hl-4-56><a class=lnlinks href=#hl-4-56>56</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-4-57><a class=lnlinks href=#hl-4-57>57</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-4-58><a class=lnlinks href=#hl-4-58>58</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-4-59><a class=lnlinks href=#hl-4-59>59</a></span><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Expand the below block to view the full <code>fn.go</code>, including imports and commentary explaining the function’s logic.</p><div class="accordion mb-3" id=the-full-fngo-file-1322-Parent><div class=accordion-item><h2 class=accordion-header id=the-full-fngo-file-1322><button class="accordion-button collapsed" type=button data-bs-toggle=collapse data-bs-target=#the-full-fngo-file-1322-Content aria-expanded=false aria-controls=the-full-fngo-file-1322-Content> The full fn.go file</button></h2><div id=the-full-fngo-file-1322-Content class="accordion-collapse collapse" aria-labelledby=the-full-fngo-file-1322 data-bs-parent=#the-full-fngo-file-1322-Parent><div class="accordion-body rounded-bottom"><div class=highlight><pre tabindex=0 class=chroma><code class=language-go data-lang=go><span class=line><span class=ln id=hl-0-1><a class=lnlinks href=#hl-0-1> 1</a></span><span class=cl><span class=kn>package</span> <span class=nx>main</span> </span></span><span class=line><span class=ln id=hl-0-2><a class=lnlinks href=#hl-0-2> 2</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-3><a class=lnlinks href=#hl-0-3> 3</a></span><span class=cl><span class=kn>import</span> <span class=p>(</span> </span></span><span class=line><span class=ln id=hl-0-4><a class=lnlinks href=#hl-0-4> 4</a></span><span class=cl> <span class=s>"context"</span> </span></span><span class=line><span class=ln id=hl-0-5><a class=lnlinks href=#hl-0-5> 5</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-6><a class=lnlinks href=#hl-0-6> 6</a></span><span class=cl> <span class=nx>metav1</span> <span class=s>"k8s.io/apimachinery/pkg/apis/meta/v1"</span> </span></span><span class=line><span class=ln id=hl-0-7><a class=lnlinks href=#hl-0-7> 7</a></span><span class=cl> <span class=s>"k8s.io/utils/ptr"</span> </span></span><span class=line><span class=ln id=hl-0-8><a class=lnlinks href=#hl-0-8> 8</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-9><a class=lnlinks href=#hl-0-9> 9</a></span><span class=cl> <span class=s>"github.com/upbound/provider-aws/apis/s3/v1beta1"</span> </span></span><span class=line><span class=ln id=hl-0-10><a class=lnlinks href=#hl-0-10> 10</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-11><a class=lnlinks href=#hl-0-11> 11</a></span><span class=cl> <span class=s>"github.com/crossplane/function-sdk-go/errors"</span> </span></span><span class=line><span class=ln id=hl-0-12><a class=lnlinks href=#hl-0-12> 12</a></span><span class=cl> <span class=s>"github.com/crossplane/function-sdk-go/logging"</span> </span></span><span class=line><span class=ln id=hl-0-13><a class=lnlinks href=#hl-0-13> 13</a></span><span class=cl> <span class=nx>fnv1beta1</span> <span class=s>"github.com/crossplane/function-sdk-go/proto/v1beta1"</span> </span></span><span class=line><span class=ln id=hl-0-14><a class=lnlinks href=#hl-0-14> 14</a></span><span class=cl> <span class=s>"github.com/crossplane/function-sdk-go/request"</span> </span></span><span class=line><span class=ln id=hl-0-15><a class=lnlinks href=#hl-0-15> 15</a></span><span class=cl> <span class=s>"github.com/crossplane/function-sdk-go/resource"</span> </span></span><span class=line><span class=ln id=hl-0-16><a class=lnlinks href=#hl-0-16> 16</a></span><span class=cl> <span class=s>"github.com/crossplane/function-sdk-go/resource/composed"</span> </span></span><span class=line><span class=ln id=hl-0-17><a class=lnlinks href=#hl-0-17> 17</a></span><span class=cl> <span class=s>"github.com/crossplane/function-sdk-go/response"</span> </span></span><span class=line><span class=ln id=hl-0-18><a class=lnlinks href=#hl-0-18> 18</a></span><span class=cl><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-19><a class=lnlinks href=#hl-0-19> 19</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-20><a class=lnlinks href=#hl-0-20> 20</a></span><span class=cl><span class=c1>// Function returns whatever response you ask it to. </span></span></span><span class=line><span class=ln id=hl-0-21><a class=lnlinks href=#hl-0-21> 21</a></span><span class=cl><span class=c1></span><span class=kd>type</span> <span class=nx>Function</span> <span class=kd>struct</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-22><a class=lnlinks href=#hl-0-22> 22</a></span><span class=cl> <span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>UnimplementedFunctionRunnerServiceServer</span> </span></span><span class=line><span class=ln id=hl-0-23><a class=lnlinks href=#hl-0-23> 23</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-24><a class=lnlinks href=#hl-0-24> 24</a></span><span class=cl> <span class=nx>log</span> <span class=nx>logging</span><span class=p>.</span><span class=nx>Logger</span> </span></span><span class=line><span class=ln id=hl-0-25><a class=lnlinks href=#hl-0-25> 25</a></span><span class=cl><span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-26><a class=lnlinks href=#hl-0-26> 26</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-27><a class=lnlinks href=#hl-0-27> 27</a></span><span class=cl><span class=c1>// RunFunction observes an XBuckets composite resource (XR). It adds an S3 </span></span></span><span class=line><span class=ln id=hl-0-28><a class=lnlinks href=#hl-0-28> 28</a></span><span class=cl><span class=c1>// bucket to the desired state for every entry in the XR's spec.names array. </span></span></span><span class=line><span class=ln id=hl-0-29><a class=lnlinks href=#hl-0-29> 29</a></span><span class=cl><span class=c1></span><span class=kd>func</span> <span class=p>(</span><span class=nx>f</span> <span class=o>*</span><span class=nx>Function</span><span class=p>)</span> <span class=nf>RunFunction</span><span class=p>(</span><span class=nx>_</span> <span class=nx>context</span><span class=p>.</span><span class=nx>Context</span><span class=p>,</span> <span class=nx>req</span> <span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionRequest</span><span class=p>)</span> <span class=p>(</span><span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionResponse</span><span class=p>,</span> <span class=kt>error</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-30><a class=lnlinks href=#hl-0-30> 30</a></span><span class=cl> <span class=nx>f</span><span class=p>.</span><span class=nx>log</span><span class=p>.</span><span class=nf>Info</span><span class=p>(</span><span class=s>"Running Function"</span><span class=p>,</span> <span class=s>"tag"</span><span class=p>,</span> <span class=nx>req</span><span class=p>.</span><span class=nf>GetMeta</span><span class=p>().</span><span class=nf>GetTag</span><span class=p>())</span> </span></span><span class=line><span class=ln id=hl-0-31><a class=lnlinks href=#hl-0-31> 31</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-32><a class=lnlinks href=#hl-0-32> 32</a></span><span class=cl> <span class=c1>// Create a response to the request. This copies the desired state and </span></span></span><span class=line><span class=ln id=hl-0-33><a class=lnlinks href=#hl-0-33> 33</a></span><span class=cl><span class=c1></span> <span class=c1>// pipeline context from the request to the response. </span></span></span><span class=line><span class=ln id=hl-0-34><a class=lnlinks href=#hl-0-34> 34</a></span><span class=cl><span class=c1></span> <span class=nx>rsp</span> <span class=o>:=</span> <span class=nx>response</span><span class=p>.</span><span class=nf>To</span><span class=p>(</span><span class=nx>req</span><span class=p>,</span> <span class=nx>response</span><span class=p>.</span><span class=nx>DefaultTTL</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-35><a class=lnlinks href=#hl-0-35> 35</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-36><a class=lnlinks href=#hl-0-36> 36</a></span><span class=cl> <span class=c1>// Read the observed XR from the request. Most functions use the observed XR </span></span></span><span class=line><span class=ln id=hl-0-37><a class=lnlinks href=#hl-0-37> 37</a></span><span class=cl><span class=c1></span> <span class=c1>// to add desired managed resources. </span></span></span><span class=line><span class=ln id=hl-0-38><a class=lnlinks href=#hl-0-38> 38</a></span><span class=cl><span class=c1></span> <span class=nx>xr</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>request</span><span class=p>.</span><span class=nf>GetObservedCompositeResource</span><span class=p>(</span><span class=nx>req</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-39><a class=lnlinks href=#hl-0-39> 39</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-40><a class=lnlinks href=#hl-0-40> 40</a></span><span class=cl> <span class=c1>// If the function can't read the XR, the request is malformed. This </span></span></span><span class=line><span class=ln id=hl-0-41><a class=lnlinks href=#hl-0-41> 41</a></span><span class=cl><span class=c1></span> <span class=c1>// should never happen. The function returns a fatal result. This tells </span></span></span><span class=line><span class=ln id=hl-0-42><a class=lnlinks href=#hl-0-42> 42</a></span><span class=cl><span class=c1></span> <span class=c1>// Crossplane to stop running functions and return an error. </span></span></span><span class=line><span class=ln id=hl-0-43><a class=lnlinks href=#hl-0-43> 43</a></span><span class=cl><span class=c1></span> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot get observed composite resource from %T"</span><span class=p>,</span> <span class=nx>req</span><span class=p>))</span> </span></span><span class=line><span class=ln id=hl-0-44><a class=lnlinks href=#hl-0-44> 44</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-0-45><a class=lnlinks href=#hl-0-45> 45</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-46><a class=lnlinks href=#hl-0-46> 46</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-47><a class=lnlinks href=#hl-0-47> 47</a></span><span class=cl> <span class=c1>// Create an updated logger with useful information about the XR. </span></span></span><span class=line><span class=ln id=hl-0-48><a class=lnlinks href=#hl-0-48> 48</a></span><span class=cl><span class=c1></span> <span class=nx>log</span> <span class=o>:=</span> <span class=nx>f</span><span class=p>.</span><span class=nx>log</span><span class=p>.</span><span class=nf>WithValues</span><span class=p>(</span> </span></span><span class=line><span class=ln id=hl-0-49><a class=lnlinks href=#hl-0-49> 49</a></span><span class=cl> <span class=s>"xr-version"</span><span class=p>,</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetAPIVersion</span><span class=p>(),</span> </span></span><span class=line><span class=ln id=hl-0-50><a class=lnlinks href=#hl-0-50> 50</a></span><span class=cl> <span class=s>"xr-kind"</span><span class=p>,</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetKind</span><span class=p>(),</span> </span></span><span class=line><span class=ln id=hl-0-51><a class=lnlinks href=#hl-0-51> 51</a></span><span class=cl> <span class=s>"xr-name"</span><span class=p>,</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetName</span><span class=p>(),</span> </span></span><span class=line><span class=ln id=hl-0-52><a class=lnlinks href=#hl-0-52> 52</a></span><span class=cl> <span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-53><a class=lnlinks href=#hl-0-53> 53</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-54><a class=lnlinks href=#hl-0-54> 54</a></span><span class=cl> <span class=c1>// Get the region from the XR. The XR has getter methods like GetString, </span></span></span><span class=line><span class=ln id=hl-0-55><a class=lnlinks href=#hl-0-55> 55</a></span><span class=cl><span class=c1></span> <span class=c1>// GetBool, etc. You can use them to get values by their field path. </span></span></span><span class=line><span class=ln id=hl-0-56><a class=lnlinks href=#hl-0-56> 56</a></span><span class=cl><span class=c1></span> <span class=nx>region</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetString</span><span class=p>(</span><span class=s>"spec.region"</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-57><a class=lnlinks href=#hl-0-57> 57</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-58><a class=lnlinks href=#hl-0-58> 58</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot read spec.region field of %s"</span><span class=p>,</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetKind</span><span class=p>()))</span> </span></span><span class=line><span class=ln id=hl-0-59><a class=lnlinks href=#hl-0-59> 59</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-0-60><a class=lnlinks href=#hl-0-60> 60</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-61><a class=lnlinks href=#hl-0-61> 61</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-62><a class=lnlinks href=#hl-0-62> 62</a></span><span class=cl> <span class=c1>// Get the array of bucket names from the XR. </span></span></span><span class=line><span class=ln id=hl-0-63><a class=lnlinks href=#hl-0-63> 63</a></span><span class=cl><span class=c1></span> <span class=nx>names</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetStringArray</span><span class=p>(</span><span class=s>"spec.names"</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-64><a class=lnlinks href=#hl-0-64> 64</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-65><a class=lnlinks href=#hl-0-65> 65</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot read spec.names field of %s"</span><span class=p>,</span> <span class=nx>xr</span><span class=p>.</span><span class=nx>Resource</span><span class=p>.</span><span class=nf>GetKind</span><span class=p>()))</span> </span></span><span class=line><span class=ln id=hl-0-66><a class=lnlinks href=#hl-0-66> 66</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-0-67><a class=lnlinks href=#hl-0-67> 67</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-68><a class=lnlinks href=#hl-0-68> 68</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-69><a class=lnlinks href=#hl-0-69> 69</a></span><span class=cl> <span class=c1>// Get all desired composed resources from the request. The function will </span></span></span><span class=line><span class=ln id=hl-0-70><a class=lnlinks href=#hl-0-70> 70</a></span><span class=cl><span class=c1></span> <span class=c1>// update this map of resources, then save it. This get, update, set pattern </span></span></span><span class=line><span class=ln id=hl-0-71><a class=lnlinks href=#hl-0-71> 71</a></span><span class=cl><span class=c1></span> <span class=c1>// ensures the function keeps any resources added by other functions. </span></span></span><span class=line><span class=ln id=hl-0-72><a class=lnlinks href=#hl-0-72> 72</a></span><span class=cl><span class=c1></span> <span class=nx>desired</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>request</span><span class=p>.</span><span class=nf>GetDesiredComposedResources</span><span class=p>(</span><span class=nx>req</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-73><a class=lnlinks href=#hl-0-73> 73</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-74><a class=lnlinks href=#hl-0-74> 74</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot get desired resources from %T"</span><span class=p>,</span> <span class=nx>req</span><span class=p>))</span> </span></span><span class=line><span class=ln id=hl-0-75><a class=lnlinks href=#hl-0-75> 75</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-0-76><a class=lnlinks href=#hl-0-76> 76</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-77><a class=lnlinks href=#hl-0-77> 77</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-78><a class=lnlinks href=#hl-0-78> 78</a></span><span class=cl> <span class=c1>// Add v1beta1 types (including Bucket) to the composed resource scheme. </span></span></span><span class=line><span class=ln id=hl-0-79><a class=lnlinks href=#hl-0-79> 79</a></span><span class=cl><span class=c1></span> <span class=c1>// composed.From uses this to automatically set apiVersion and kind. </span></span></span><span class=line><span class=ln id=hl-0-80><a class=lnlinks href=#hl-0-80> 80</a></span><span class=cl><span class=c1></span> <span class=nx>_</span> <span class=p>=</span> <span class=nx>v1beta1</span><span class=p>.</span><span class=nf>AddToScheme</span><span class=p>(</span><span class=nx>composed</span><span class=p>.</span><span class=nx>Scheme</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-81><a class=lnlinks href=#hl-0-81> 81</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-82><a class=lnlinks href=#hl-0-82> 82</a></span><span class=cl> <span class=c1>// Add a desired S3 bucket for each name. </span></span></span><span class=line><span class=ln id=hl-0-83><a class=lnlinks href=#hl-0-83> 83</a></span><span class=cl><span class=c1></span> <span class=k>for</span> <span class=nx>_</span><span class=p>,</span> <span class=nx>name</span> <span class=o>:=</span> <span class=k>range</span> <span class=nx>names</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-84><a class=lnlinks href=#hl-0-84> 84</a></span><span class=cl> <span class=c1>// One advantage of writing a function in Go is strong typing. The </span></span></span><span class=line><span class=ln id=hl-0-85><a class=lnlinks href=#hl-0-85> 85</a></span><span class=cl><span class=c1></span> <span class=c1>// function can import and use managed resource types from the provider. </span></span></span><span class=line><span class=ln id=hl-0-86><a class=lnlinks href=#hl-0-86> 86</a></span><span class=cl><span class=c1></span> <span class=nx>b</span> <span class=o>:=</span> <span class=o>&</span><span class=nx>v1beta1</span><span class=p>.</span><span class=nx>Bucket</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-87><a class=lnlinks href=#hl-0-87> 87</a></span><span class=cl> <span class=nx>ObjectMeta</span><span class=p>:</span> <span class=nx>metav1</span><span class=p>.</span><span class=nx>ObjectMeta</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-88><a class=lnlinks href=#hl-0-88> 88</a></span><span class=cl> <span class=c1>// Set the external name annotation to the desired bucket name. </span></span></span><span class=line><span class=ln id=hl-0-89><a class=lnlinks href=#hl-0-89> 89</a></span><span class=cl><span class=c1></span> <span class=c1>// This controls what the bucket will be named in AWS. </span></span></span><span class=line><span class=ln id=hl-0-90><a class=lnlinks href=#hl-0-90> 90</a></span><span class=cl><span class=c1></span> <span class=nx>Annotations</span><span class=p>:</span> <span class=kd>map</span><span class=p>[</span><span class=kt>string</span><span class=p>]</span><span class=kt>string</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-91><a class=lnlinks href=#hl-0-91> 91</a></span><span class=cl> <span class=s>"crossplane.io/external-name"</span><span class=p>:</span> <span class=nx>name</span><span class=p>,</span> </span></span><span class=line><span class=ln id=hl-0-92><a class=lnlinks href=#hl-0-92> 92</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-93><a class=lnlinks href=#hl-0-93> 93</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-94><a class=lnlinks href=#hl-0-94> 94</a></span><span class=cl> <span class=nx>Spec</span><span class=p>:</span> <span class=nx>v1beta1</span><span class=p>.</span><span class=nx>BucketSpec</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-95><a class=lnlinks href=#hl-0-95> 95</a></span><span class=cl> <span class=nx>ForProvider</span><span class=p>:</span> <span class=nx>v1beta1</span><span class=p>.</span><span class=nx>BucketParameters</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-96><a class=lnlinks href=#hl-0-96> 96</a></span><span class=cl> <span class=c1>// Set the bucket's region to the value read from the XR. </span></span></span><span class=line><span class=ln id=hl-0-97><a class=lnlinks href=#hl-0-97> 97</a></span><span class=cl><span class=c1></span> <span class=nx>Region</span><span class=p>:</span> <span class=nx>ptr</span><span class=p>.</span><span class=nx>To</span><span class=p>[</span><span class=kt>string</span><span class=p>](</span><span class=nx>region</span><span class=p>),</span> </span></span><span class=line><span class=ln id=hl-0-98><a class=lnlinks href=#hl-0-98> 98</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-99><a class=lnlinks href=#hl-0-99> 99</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-100><a class=lnlinks href=#hl-0-100>100</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-101><a class=lnlinks href=#hl-0-101>101</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-102><a class=lnlinks href=#hl-0-102>102</a></span><span class=cl> <span class=c1>// Convert the bucket to the unstructured resource data format the SDK </span></span></span><span class=line><span class=ln id=hl-0-103><a class=lnlinks href=#hl-0-103>103</a></span><span class=cl><span class=c1></span> <span class=c1>// uses to store desired composed resources. </span></span></span><span class=line><span class=ln id=hl-0-104><a class=lnlinks href=#hl-0-104>104</a></span><span class=cl><span class=c1></span> <span class=nx>cd</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>composed</span><span class=p>.</span><span class=nf>From</span><span class=p>(</span><span class=nx>b</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-105><a class=lnlinks href=#hl-0-105>105</a></span><span class=cl> <span class=k>if</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-106><a class=lnlinks href=#hl-0-106>106</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot convert %T to %T"</span><span class=p>,</span> <span class=nx>b</span><span class=p>,</span> <span class=o>&</span><span class=nx>composed</span><span class=p>.</span><span class=nx>Unstructured</span><span class=p>{}))</span> </span></span><span class=line><span class=ln id=hl-0-107><a class=lnlinks href=#hl-0-107>107</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-0-108><a class=lnlinks href=#hl-0-108>108</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-109><a class=lnlinks href=#hl-0-109>109</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-110><a class=lnlinks href=#hl-0-110>110</a></span><span class=cl> <span class=c1>// Add the bucket to the map of desired composed resources. It's </span></span></span><span class=line><span class=ln id=hl-0-111><a class=lnlinks href=#hl-0-111>111</a></span><span class=cl><span class=c1></span> <span class=c1>// important that the function adds the same bucket every time it's </span></span></span><span class=line><span class=ln id=hl-0-112><a class=lnlinks href=#hl-0-112>112</a></span><span class=cl><span class=c1></span> <span class=c1>// called. It's also important that the bucket is added with the same </span></span></span><span class=line><span class=ln id=hl-0-113><a class=lnlinks href=#hl-0-113>113</a></span><span class=cl><span class=c1></span> <span class=c1>// resource.Name every time it's called. The function prefixes the name </span></span></span><span class=line><span class=ln id=hl-0-114><a class=lnlinks href=#hl-0-114>114</a></span><span class=cl><span class=c1></span> <span class=c1>// with "xbuckets-" to avoid collisions with any other composed </span></span></span><span class=line><span class=ln id=hl-0-115><a class=lnlinks href=#hl-0-115>115</a></span><span class=cl><span class=c1></span> <span class=c1>// resources that might be in the desired resources map. </span></span></span><span class=line><span class=ln id=hl-0-116><a class=lnlinks href=#hl-0-116>116</a></span><span class=cl><span class=c1></span> <span class=nx>desired</span><span class=p>[</span><span class=nx>resource</span><span class=p>.</span><span class=nf>Name</span><span class=p>(</span><span class=s>"xbuckets-"</span><span class=o>+</span><span class=nx>name</span><span class=p>)]</span> <span class=p>=</span> <span class=o>&</span><span class=nx>resource</span><span class=p>.</span><span class=nx>DesiredComposed</span><span class=p>{</span><span class=nx>Resource</span><span class=p>:</span> <span class=nx>cd</span><span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-117><a class=lnlinks href=#hl-0-117>117</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-118><a class=lnlinks href=#hl-0-118>118</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-119><a class=lnlinks href=#hl-0-119>119</a></span><span class=cl> <span class=c1>// Finally, save the updated desired composed resources to the response. </span></span></span><span class=line><span class=ln id=hl-0-120><a class=lnlinks href=#hl-0-120>120</a></span><span class=cl><span class=c1></span> <span class=k>if</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>response</span><span class=p>.</span><span class=nf>SetDesiredComposedResources</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>desired</span><span class=p>);</span> <span class=nx>err</span> <span class=o>!=</span> <span class=kc>nil</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-121><a class=lnlinks href=#hl-0-121>121</a></span><span class=cl> <span class=nx>response</span><span class=p>.</span><span class=nf>Fatal</span><span class=p>(</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>errors</span><span class=p>.</span><span class=nf>Wrapf</span><span class=p>(</span><span class=nx>err</span><span class=p>,</span> <span class=s>"cannot set desired composed resources in %T"</span><span class=p>,</span> <span class=nx>rsp</span><span class=p>))</span> </span></span><span class=line><span class=ln id=hl-0-122><a class=lnlinks href=#hl-0-122>122</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-0-123><a class=lnlinks href=#hl-0-123>123</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-124><a class=lnlinks href=#hl-0-124>124</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-125><a class=lnlinks href=#hl-0-125>125</a></span><span class=cl> <span class=c1>// Log what the function did. This will only appear in the function's pod </span></span></span><span class=line><span class=ln id=hl-0-126><a class=lnlinks href=#hl-0-126>126</a></span><span class=cl><span class=c1></span> <span class=c1>// logs. A function can use response.Normal and response.Warning to emit </span></span></span><span class=line><span class=ln id=hl-0-127><a class=lnlinks href=#hl-0-127>127</a></span><span class=cl><span class=c1></span> <span class=c1>// Kubernetes events associated with the XR it's operating on. </span></span></span><span class=line><span class=ln id=hl-0-128><a class=lnlinks href=#hl-0-128>128</a></span><span class=cl><span class=c1></span> <span class=nx>log</span><span class=p>.</span><span class=nf>Info</span><span class=p>(</span><span class=s>"Added desired buckets"</span><span class=p>,</span> <span class=s>"region"</span><span class=p>,</span> <span class=nx>region</span><span class=p>,</span> <span class=s>"count"</span><span class=p>,</span> <span class=nb>len</span><span class=p>(</span><span class=nx>names</span><span class=p>))</span> </span></span><span class=line><span class=ln id=hl-0-129><a class=lnlinks href=#hl-0-129>129</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-130><a class=lnlinks href=#hl-0-130>130</a></span><span class=cl> <span class=k>return</span> <span class=nx>rsp</span><span class=p>,</span> <span class=kc>nil</span> </span></span><span class=line><span class=ln id=hl-0-131><a class=lnlinks href=#hl-0-131>131</a></span><span class=cl><span class=p>}</span> </span></span></code></pre></div></div></div></div></div><p>This code:</p><ol><li>Gets the observed composite resource from the <code>RunFunctionRequest</code>.</li><li>Gets the region and bucket names from the observed composite resource.</li><li>Adds one desired S3 bucket for each bucket name.</li><li>Returns the desired S3 buckets in a <code>RunFunctionResponse</code>.</li></ol><p>The code uses the <code>v1beta1.Bucket</code> type from <a href=https://github.com/upbound/provider-aws>Upbound’s AWS S3 provider</a>. One advantage of writing a function in Go is that you can compose resources using the same strongly typed structs Crossplane uses in its providers.</p><p>You must get the AWS Provider Go module to use this type:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-5-1><a class=lnlinks href=#hl-5-1>1</a></span><span class=cl>go get github.com/upbound/provider-aws@v0.43.0 </span></span></code></pre></div><p>Crossplane provides a <a href=https://github.com/crossplane/function-sdk-go>software development kit</a> (SDK) for writing composition functions in <a href=https://go.dev>Go</a>. This function uses utilities from the SDK. In particular the <code>request</code> and <code>response</code> packages make working with the <code>RunFunctionRequest</code> and <code>RunFunctionResponse</code> types easier.</p><div class="admonition tip d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="tip:"><use xlink:href="#check"/></svg><span class=ps-1>Tip</span></div><div class=admonition-content>Read the <a href=https://pkg.go.dev/github.com/crossplane/function-sdk-go>Go package documentation</a> for the SDK.</div></div><h2 id=test-the-function-end-to-end>Test the function end-to-end <a class=anchor-link id=test-the-function-end-to-end href=#test-the-function-end-to-end aria-label="Link to this section: Test the function end-to-end"></a></h2><p>Test your function by adding unit tests, and by using the <code>crossplane beta render</code> command.</p><p>Go has rich support for unit testing. When you initialize a function from the template it adds some unit tests to <code>fn_test.go</code>. These tests follow Go’s <a href=https://github.com/golang/go/wiki/TestComments>recommendations</a>. They use only <a href=https://pkg.go.dev/testing><code>pkg/testing</code></a> from the Go standard library and <a href=https://pkg.go.dev/github.com/google/go-cmp/cmp><code>google/go-cmp</code></a>.</p><p>To add test cases, update the <code>cases</code> map in <code>TestRunFunction</code>. Expand the below block to view the full <code>fn_test.go</code> file for the function.</p><div class="accordion mb-3" id=the-full-fn_testgo-file-1362-Parent><div class=accordion-item><h2 class=accordion-header id=the-full-fn_testgo-file-1362><button class="accordion-button collapsed" type=button data-bs-toggle=collapse data-bs-target=#the-full-fn_testgo-file-1362-Content aria-expanded=false aria-controls=the-full-fn_testgo-file-1362-Content> The full fn_test.go file</button></h2><div id=the-full-fn_testgo-file-1362-Content class="accordion-collapse collapse" aria-labelledby=the-full-fn_testgo-file-1362 data-bs-parent=#the-full-fn_testgo-file-1362-Parent><div class="accordion-body rounded-bottom"><div class=highlight><pre tabindex=0 class=chroma><code class=language-go data-lang=go><span class=line><span class=ln id=hl-0-1><a class=lnlinks href=#hl-0-1> 1</a></span><span class=cl><span class=kn>package</span> <span class=nx>main</span> </span></span><span class=line><span class=ln id=hl-0-2><a class=lnlinks href=#hl-0-2> 2</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-3><a class=lnlinks href=#hl-0-3> 3</a></span><span class=cl><span class=kn>import</span> <span class=p>(</span> </span></span><span class=line><span class=ln id=hl-0-4><a class=lnlinks href=#hl-0-4> 4</a></span><span class=cl> <span class=s>"context"</span> </span></span><span class=line><span class=ln id=hl-0-5><a class=lnlinks href=#hl-0-5> 5</a></span><span class=cl> <span class=s>"testing"</span> </span></span><span class=line><span class=ln id=hl-0-6><a class=lnlinks href=#hl-0-6> 6</a></span><span class=cl> <span class=s>"time"</span> </span></span><span class=line><span class=ln id=hl-0-7><a class=lnlinks href=#hl-0-7> 7</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-8><a class=lnlinks href=#hl-0-8> 8</a></span><span class=cl> <span class=s>"github.com/google/go-cmp/cmp"</span> </span></span><span class=line><span class=ln id=hl-0-9><a class=lnlinks href=#hl-0-9> 9</a></span><span class=cl> <span class=s>"github.com/google/go-cmp/cmp/cmpopts"</span> </span></span><span class=line><span class=ln id=hl-0-10><a class=lnlinks href=#hl-0-10> 10</a></span><span class=cl> <span class=s>"google.golang.org/protobuf/testing/protocmp"</span> </span></span><span class=line><span class=ln id=hl-0-11><a class=lnlinks href=#hl-0-11> 11</a></span><span class=cl> <span class=s>"google.golang.org/protobuf/types/known/durationpb"</span> </span></span><span class=line><span class=ln id=hl-0-12><a class=lnlinks href=#hl-0-12> 12</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-13><a class=lnlinks href=#hl-0-13> 13</a></span><span class=cl> <span class=s>"github.com/crossplane/crossplane-runtime/pkg/logging"</span> </span></span><span class=line><span class=ln id=hl-0-14><a class=lnlinks href=#hl-0-14> 14</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-15><a class=lnlinks href=#hl-0-15> 15</a></span><span class=cl> <span class=nx>fnv1beta1</span> <span class=s>"github.com/crossplane/function-sdk-go/proto/v1beta1"</span> </span></span><span class=line><span class=ln id=hl-0-16><a class=lnlinks href=#hl-0-16> 16</a></span><span class=cl> <span class=s>"github.com/crossplane/function-sdk-go/resource"</span> </span></span><span class=line><span class=ln id=hl-0-17><a class=lnlinks href=#hl-0-17> 17</a></span><span class=cl><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-18><a class=lnlinks href=#hl-0-18> 18</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-19><a class=lnlinks href=#hl-0-19> 19</a></span><span class=cl><span class=kd>func</span> <span class=nf>TestRunFunction</span><span class=p>(</span><span class=nx>t</span> <span class=o>*</span><span class=nx>testing</span><span class=p>.</span><span class=nx>T</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-20><a class=lnlinks href=#hl-0-20> 20</a></span><span class=cl> <span class=kd>type</span> <span class=nx>args</span> <span class=kd>struct</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-21><a class=lnlinks href=#hl-0-21> 21</a></span><span class=cl> <span class=nx>ctx</span> <span class=nx>context</span><span class=p>.</span><span class=nx>Context</span> </span></span><span class=line><span class=ln id=hl-0-22><a class=lnlinks href=#hl-0-22> 22</a></span><span class=cl> <span class=nx>req</span> <span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionRequest</span> </span></span><span class=line><span class=ln id=hl-0-23><a class=lnlinks href=#hl-0-23> 23</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-24><a class=lnlinks href=#hl-0-24> 24</a></span><span class=cl> <span class=kd>type</span> <span class=nx>want</span> <span class=kd>struct</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-25><a class=lnlinks href=#hl-0-25> 25</a></span><span class=cl> <span class=nx>rsp</span> <span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionResponse</span> </span></span><span class=line><span class=ln id=hl-0-26><a class=lnlinks href=#hl-0-26> 26</a></span><span class=cl> <span class=nx>err</span> <span class=kt>error</span> </span></span><span class=line><span class=ln id=hl-0-27><a class=lnlinks href=#hl-0-27> 27</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-28><a class=lnlinks href=#hl-0-28> 28</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-29><a class=lnlinks href=#hl-0-29> 29</a></span><span class=cl> <span class=nx>cases</span> <span class=o>:=</span> <span class=kd>map</span><span class=p>[</span><span class=kt>string</span><span class=p>]</span><span class=kd>struct</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-30><a class=lnlinks href=#hl-0-30> 30</a></span><span class=cl> <span class=nx>reason</span> <span class=kt>string</span> </span></span><span class=line><span class=ln id=hl-0-31><a class=lnlinks href=#hl-0-31> 31</a></span><span class=cl> <span class=nx>args</span> <span class=nx>args</span> </span></span><span class=line><span class=ln id=hl-0-32><a class=lnlinks href=#hl-0-32> 32</a></span><span class=cl> <span class=nx>want</span> <span class=nx>want</span> </span></span><span class=line><span class=ln id=hl-0-33><a class=lnlinks href=#hl-0-33> 33</a></span><span class=cl> <span class=p>}{</span> </span></span><span class=line><span class=ln id=hl-0-34><a class=lnlinks href=#hl-0-34> 34</a></span><span class=cl> <span class=s>"AddTwoBuckets"</span><span class=p>:</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-35><a class=lnlinks href=#hl-0-35> 35</a></span><span class=cl> <span class=nx>reason</span><span class=p>:</span> <span class=s>"The Function should add two buckets to the desired composed resources"</span><span class=p>,</span> </span></span><span class=line><span class=ln id=hl-0-36><a class=lnlinks href=#hl-0-36> 36</a></span><span class=cl> <span class=nx>args</span><span class=p>:</span> <span class=nx>args</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-37><a class=lnlinks href=#hl-0-37> 37</a></span><span class=cl> <span class=nx>req</span><span class=p>:</span> <span class=o>&</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionRequest</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-38><a class=lnlinks href=#hl-0-38> 38</a></span><span class=cl> <span class=nx>Observed</span><span class=p>:</span> <span class=o>&</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>State</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-39><a class=lnlinks href=#hl-0-39> 39</a></span><span class=cl> <span class=nx>Composite</span><span class=p>:</span> <span class=o>&</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>Resource</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-40><a class=lnlinks href=#hl-0-40> 40</a></span><span class=cl> <span class=c1>// MustStructJSON is a handy way to provide mock </span></span></span><span class=line><span class=ln id=hl-0-41><a class=lnlinks href=#hl-0-41> 41</a></span><span class=cl><span class=c1></span> <span class=c1>// resources. </span></span></span><span class=line><span class=ln id=hl-0-42><a class=lnlinks href=#hl-0-42> 42</a></span><span class=cl><span class=c1></span> <span class=nx>Resource</span><span class=p>:</span> <span class=nx>resource</span><span class=p>.</span><span class=nf>MustStructJSON</span><span class=p>(</span><span class=s>`{ </span></span></span><span class=line><span class=ln id=hl-0-43><a class=lnlinks href=#hl-0-43> 43</a></span><span class=cl><span class=s> "apiVersion": "example.crossplane.io/v1alpha1", </span></span></span><span class=line><span class=ln id=hl-0-44><a class=lnlinks href=#hl-0-44> 44</a></span><span class=cl><span class=s> "kind": "XBuckets", </span></span></span><span class=line><span class=ln id=hl-0-45><a class=lnlinks href=#hl-0-45> 45</a></span><span class=cl><span class=s> "metadata": { </span></span></span><span class=line><span class=ln id=hl-0-46><a class=lnlinks href=#hl-0-46> 46</a></span><span class=cl><span class=s> "name": "test" </span></span></span><span class=line><span class=ln id=hl-0-47><a class=lnlinks href=#hl-0-47> 47</a></span><span class=cl><span class=s> }, </span></span></span><span class=line><span class=ln id=hl-0-48><a class=lnlinks href=#hl-0-48> 48</a></span><span class=cl><span class=s> "spec": { </span></span></span><span class=line><span class=ln id=hl-0-49><a class=lnlinks href=#hl-0-49> 49</a></span><span class=cl><span class=s> "region": "us-east-2", </span></span></span><span class=line><span class=ln id=hl-0-50><a class=lnlinks href=#hl-0-50> 50</a></span><span class=cl><span class=s> "names": [ </span></span></span><span class=line><span class=ln id=hl-0-51><a class=lnlinks href=#hl-0-51> 51</a></span><span class=cl><span class=s> "test-bucket-a", </span></span></span><span class=line><span class=ln id=hl-0-52><a class=lnlinks href=#hl-0-52> 52</a></span><span class=cl><span class=s> "test-bucket-b" </span></span></span><span class=line><span class=ln id=hl-0-53><a class=lnlinks href=#hl-0-53> 53</a></span><span class=cl><span class=s> ] </span></span></span><span class=line><span class=ln id=hl-0-54><a class=lnlinks href=#hl-0-54> 54</a></span><span class=cl><span class=s> } </span></span></span><span class=line><span class=ln id=hl-0-55><a class=lnlinks href=#hl-0-55> 55</a></span><span class=cl><span class=s> }`</span><span class=p>),</span> </span></span><span class=line><span class=ln id=hl-0-56><a class=lnlinks href=#hl-0-56> 56</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-57><a class=lnlinks href=#hl-0-57> 57</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-58><a class=lnlinks href=#hl-0-58> 58</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-59><a class=lnlinks href=#hl-0-59> 59</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-60><a class=lnlinks href=#hl-0-60> 60</a></span><span class=cl> <span class=nx>want</span><span class=p>:</span> <span class=nx>want</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-61><a class=lnlinks href=#hl-0-61> 61</a></span><span class=cl> <span class=nx>rsp</span><span class=p>:</span> <span class=o>&</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>RunFunctionResponse</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-62><a class=lnlinks href=#hl-0-62> 62</a></span><span class=cl> <span class=nx>Meta</span><span class=p>:</span> <span class=o>&</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>ResponseMeta</span><span class=p>{</span><span class=nx>Ttl</span><span class=p>:</span> <span class=nx>durationpb</span><span class=p>.</span><span class=nf>New</span><span class=p>(</span><span class=mi>60</span> <span class=o>*</span> <span class=nx>time</span><span class=p>.</span><span class=nx>Second</span><span class=p>)},</span> </span></span><span class=line><span class=ln id=hl-0-63><a class=lnlinks href=#hl-0-63> 63</a></span><span class=cl> <span class=nx>Desired</span><span class=p>:</span> <span class=o>&</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>State</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-64><a class=lnlinks href=#hl-0-64> 64</a></span><span class=cl> <span class=nx>Resources</span><span class=p>:</span> <span class=kd>map</span><span class=p>[</span><span class=kt>string</span><span class=p>]</span><span class=o>*</span><span class=nx>fnv1beta1</span><span class=p>.</span><span class=nx>Resource</span><span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-65><a class=lnlinks href=#hl-0-65> 65</a></span><span class=cl> <span class=s>"xbuckets-test-bucket-a"</span><span class=p>:</span> <span class=p>{</span><span class=nx>Resource</span><span class=p>:</span> <span class=nx>resource</span><span class=p>.</span><span class=nf>MustStructJSON</span><span class=p>(</span><span class=s>`{ </span></span></span><span class=line><span class=ln id=hl-0-66><a class=lnlinks href=#hl-0-66> 66</a></span><span class=cl><span class=s> "apiVersion": "s3.aws.upbound.io/v1beta1", </span></span></span><span class=line><span class=ln id=hl-0-67><a class=lnlinks href=#hl-0-67> 67</a></span><span class=cl><span class=s> "kind": "Bucket", </span></span></span><span class=line><span class=ln id=hl-0-68><a class=lnlinks href=#hl-0-68> 68</a></span><span class=cl><span class=s> "metadata": { </span></span></span><span class=line><span class=ln id=hl-0-69><a class=lnlinks href=#hl-0-69> 69</a></span><span class=cl><span class=s> "annotations": { </span></span></span><span class=line><span class=ln id=hl-0-70><a class=lnlinks href=#hl-0-70> 70</a></span><span class=cl><span class=s> "crossplane.io/external-name": "test-bucket-a" </span></span></span><span class=line><span class=ln id=hl-0-71><a class=lnlinks href=#hl-0-71> 71</a></span><span class=cl><span class=s> } </span></span></span><span class=line><span class=ln id=hl-0-72><a class=lnlinks href=#hl-0-72> 72</a></span><span class=cl><span class=s> }, </span></span></span><span class=line><span class=ln id=hl-0-73><a class=lnlinks href=#hl-0-73> 73</a></span><span class=cl><span class=s> "spec": { </span></span></span><span class=line><span class=ln id=hl-0-74><a class=lnlinks href=#hl-0-74> 74</a></span><span class=cl><span class=s> "forProvider": { </span></span></span><span class=line><span class=ln id=hl-0-75><a class=lnlinks href=#hl-0-75> 75</a></span><span class=cl><span class=s> "region": "us-east-2" </span></span></span><span class=line><span class=ln id=hl-0-76><a class=lnlinks href=#hl-0-76> 76</a></span><span class=cl><span class=s> } </span></span></span><span class=line><span class=ln id=hl-0-77><a class=lnlinks href=#hl-0-77> 77</a></span><span class=cl><span class=s> } </span></span></span><span class=line><span class=ln id=hl-0-78><a class=lnlinks href=#hl-0-78> 78</a></span><span class=cl><span class=s> }`</span><span class=p>)},</span> </span></span><span class=line><span class=ln id=hl-0-79><a class=lnlinks href=#hl-0-79> 79</a></span><span class=cl> <span class=s>"xbuckets-test-bucket-b"</span><span class=p>:</span> <span class=p>{</span><span class=nx>Resource</span><span class=p>:</span> <span class=nx>resource</span><span class=p>.</span><span class=nf>MustStructJSON</span><span class=p>(</span><span class=s>`{ </span></span></span><span class=line><span class=ln id=hl-0-80><a class=lnlinks href=#hl-0-80> 80</a></span><span class=cl><span class=s> "apiVersion": "s3.aws.upbound.io/v1beta1", </span></span></span><span class=line><span class=ln id=hl-0-81><a class=lnlinks href=#hl-0-81> 81</a></span><span class=cl><span class=s> "kind": "Bucket", </span></span></span><span class=line><span class=ln id=hl-0-82><a class=lnlinks href=#hl-0-82> 82</a></span><span class=cl><span class=s> "metadata": { </span></span></span><span class=line><span class=ln id=hl-0-83><a class=lnlinks href=#hl-0-83> 83</a></span><span class=cl><span class=s> "annotations": { </span></span></span><span class=line><span class=ln id=hl-0-84><a class=lnlinks href=#hl-0-84> 84</a></span><span class=cl><span class=s> "crossplane.io/external-name": "test-bucket-b" </span></span></span><span class=line><span class=ln id=hl-0-85><a class=lnlinks href=#hl-0-85> 85</a></span><span class=cl><span class=s> } </span></span></span><span class=line><span class=ln id=hl-0-86><a class=lnlinks href=#hl-0-86> 86</a></span><span class=cl><span class=s> }, </span></span></span><span class=line><span class=ln id=hl-0-87><a class=lnlinks href=#hl-0-87> 87</a></span><span class=cl><span class=s> "spec": { </span></span></span><span class=line><span class=ln id=hl-0-88><a class=lnlinks href=#hl-0-88> 88</a></span><span class=cl><span class=s> "forProvider": { </span></span></span><span class=line><span class=ln id=hl-0-89><a class=lnlinks href=#hl-0-89> 89</a></span><span class=cl><span class=s> "region": "us-east-2" </span></span></span><span class=line><span class=ln id=hl-0-90><a class=lnlinks href=#hl-0-90> 90</a></span><span class=cl><span class=s> } </span></span></span><span class=line><span class=ln id=hl-0-91><a class=lnlinks href=#hl-0-91> 91</a></span><span class=cl><span class=s> } </span></span></span><span class=line><span class=ln id=hl-0-92><a class=lnlinks href=#hl-0-92> 92</a></span><span class=cl><span class=s> }`</span><span class=p>)},</span> </span></span><span class=line><span class=ln id=hl-0-93><a class=lnlinks href=#hl-0-93> 93</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-94><a class=lnlinks href=#hl-0-94> 94</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-95><a class=lnlinks href=#hl-0-95> 95</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-96><a class=lnlinks href=#hl-0-96> 96</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-97><a class=lnlinks href=#hl-0-97> 97</a></span><span class=cl> <span class=p>},</span> </span></span><span class=line><span class=ln id=hl-0-98><a class=lnlinks href=#hl-0-98> 98</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-99><a class=lnlinks href=#hl-0-99> 99</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-100><a class=lnlinks href=#hl-0-100>100</a></span><span class=cl> <span class=k>for</span> <span class=nx>name</span><span class=p>,</span> <span class=nx>tc</span> <span class=o>:=</span> <span class=k>range</span> <span class=nx>cases</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-101><a class=lnlinks href=#hl-0-101>101</a></span><span class=cl> <span class=nx>t</span><span class=p>.</span><span class=nf>Run</span><span class=p>(</span><span class=nx>name</span><span class=p>,</span> <span class=kd>func</span><span class=p>(</span><span class=nx>t</span> <span class=o>*</span><span class=nx>testing</span><span class=p>.</span><span class=nx>T</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-102><a class=lnlinks href=#hl-0-102>102</a></span><span class=cl> <span class=nx>f</span> <span class=o>:=</span> <span class=o>&</span><span class=nx>Function</span><span class=p>{</span><span class=nx>log</span><span class=p>:</span> <span class=nx>logging</span><span class=p>.</span><span class=nf>NewNopLogger</span><span class=p>()}</span> </span></span><span class=line><span class=ln id=hl-0-103><a class=lnlinks href=#hl-0-103>103</a></span><span class=cl> <span class=nx>rsp</span><span class=p>,</span> <span class=nx>err</span> <span class=o>:=</span> <span class=nx>f</span><span class=p>.</span><span class=nf>RunFunction</span><span class=p>(</span><span class=nx>tc</span><span class=p>.</span><span class=nx>args</span><span class=p>.</span><span class=nx>ctx</span><span class=p>,</span> <span class=nx>tc</span><span class=p>.</span><span class=nx>args</span><span class=p>.</span><span class=nx>req</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-104><a class=lnlinks href=#hl-0-104>104</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-105><a class=lnlinks href=#hl-0-105>105</a></span><span class=cl> <span class=k>if</span> <span class=nx>diff</span> <span class=o>:=</span> <span class=nx>cmp</span><span class=p>.</span><span class=nf>Diff</span><span class=p>(</span><span class=nx>tc</span><span class=p>.</span><span class=nx>want</span><span class=p>.</span><span class=nx>rsp</span><span class=p>,</span> <span class=nx>rsp</span><span class=p>,</span> <span class=nx>protocmp</span><span class=p>.</span><span class=nf>Transform</span><span class=p>());</span> <span class=nx>diff</span> <span class=o>!=</span> <span class=s>""</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-106><a class=lnlinks href=#hl-0-106>106</a></span><span class=cl> <span class=nx>t</span><span class=p>.</span><span class=nf>Errorf</span><span class=p>(</span><span class=s>"%s\nf.RunFunction(...): -want rsp, +got rsp:\n%s"</span><span class=p>,</span> <span class=nx>tc</span><span class=p>.</span><span class=nx>reason</span><span class=p>,</span> <span class=nx>diff</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-107><a class=lnlinks href=#hl-0-107>107</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-108><a class=lnlinks href=#hl-0-108>108</a></span><span class=cl> </span></span><span class=line><span class=ln id=hl-0-109><a class=lnlinks href=#hl-0-109>109</a></span><span class=cl> <span class=k>if</span> <span class=nx>diff</span> <span class=o>:=</span> <span class=nx>cmp</span><span class=p>.</span><span class=nf>Diff</span><span class=p>(</span><span class=nx>tc</span><span class=p>.</span><span class=nx>want</span><span class=p>.</span><span class=nx>err</span><span class=p>,</span> <span class=nx>err</span><span class=p>,</span> <span class=nx>cmpopts</span><span class=p>.</span><span class=nf>EquateErrors</span><span class=p>());</span> <span class=nx>diff</span> <span class=o>!=</span> <span class=s>""</span> <span class=p>{</span> </span></span><span class=line><span class=ln id=hl-0-110><a class=lnlinks href=#hl-0-110>110</a></span><span class=cl> <span class=nx>t</span><span class=p>.</span><span class=nf>Errorf</span><span class=p>(</span><span class=s>"%s\nf.RunFunction(...): -want err, +got err:\n%s"</span><span class=p>,</span> <span class=nx>tc</span><span class=p>.</span><span class=nx>reason</span><span class=p>,</span> <span class=nx>diff</span><span class=p>)</span> </span></span><span class=line><span class=ln id=hl-0-111><a class=lnlinks href=#hl-0-111>111</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-112><a class=lnlinks href=#hl-0-112>112</a></span><span class=cl> <span class=p>})</span> </span></span><span class=line><span class=ln id=hl-0-113><a class=lnlinks href=#hl-0-113>113</a></span><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=ln id=hl-0-114><a class=lnlinks href=#hl-0-114>114</a></span><span class=cl><span class=p>}</span> </span></span></code></pre></div></div></div></div></div><p>Run the unit tests using the <code>go test</code> command:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-6-1><a class=lnlinks href=#hl-6-1>1</a></span><span class=cl>go <span class=nb>test</span> -v -cover . </span></span><span class=line><span class=ln id=hl-6-2><a class=lnlinks href=#hl-6-2>2</a></span><span class=cl><span class=o>===</span> RUN <span class=nv>TestRunFunction</span> </span></span><span class=line><span class=ln id=hl-6-3><a class=lnlinks href=#hl-6-3>3</a></span><span class=cl><span class=o>===</span> RUN TestRunFunction/AddTwoBuckets </span></span><span class=line><span class=ln id=hl-6-4><a class=lnlinks href=#hl-6-4>4</a></span><span class=cl>--- PASS: TestRunFunction <span class=o>(</span>0.00s<span class=o>)</span> </span></span><span class=line><span class=ln id=hl-6-5><a class=lnlinks href=#hl-6-5>5</a></span><span class=cl> --- PASS: TestRunFunction/AddTwoBuckets <span class=o>(</span>0.00s<span class=o>)</span> </span></span><span class=line><span class=ln id=hl-6-6><a class=lnlinks href=#hl-6-6>6</a></span><span class=cl>PASS </span></span><span class=line><span class=ln id=hl-6-7><a class=lnlinks href=#hl-6-7>7</a></span><span class=cl>coverage: 52.6% of statements </span></span><span class=line><span class=ln id=hl-6-8><a class=lnlinks href=#hl-6-8>8</a></span><span class=cl>ok github.com/negz/function-xbuckets 0.016s coverage: 52.6% of statements </span></span></code></pre></div><p>You can preview the output of a Composition that uses this function using the Crossplane CLI. You don’t need a Crossplane control plane to do this.</p><p>Create a directory under <code>function-xbuckets</code> named <code>example</code> and create Composite Resource, Composition and Function YAML files.</p><p>Expand the following block to see example files.</p><div class="accordion mb-3" id=the-xryaml-compositionyaml-and-functionyaml-files-954-Parent><div class=accordion-item><h2 class=accordion-header id=the-xryaml-compositionyaml-and-functionyaml-files-954><button class="accordion-button collapsed" type=button data-bs-toggle=collapse data-bs-target=#the-xryaml-compositionyaml-and-functionyaml-files-954-Content aria-expanded=false aria-controls=the-xryaml-compositionyaml-and-functionyaml-files-954-Content> The xr.yaml, composition.yaml and function.yaml files</button></h2><div id=the-xryaml-compositionyaml-and-functionyaml-files-954-Content class="accordion-collapse collapse" aria-labelledby=the-xryaml-compositionyaml-and-functionyaml-files-954 data-bs-parent=#the-xryaml-compositionyaml-and-functionyaml-files-954-Parent><div class="accordion-body rounded-bottom"><p>You can recreate the output below using by running <code>crossplane beta render</code> with these files.</p><p>The <code>xr.yaml</code> file contains the composite resource to render:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-yaml data-lang=yaml><span class=line><span class=ln id=hl-0-1><a class=lnlinks href=#hl-0-1> 1</a></span><span class=cl><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>example.crossplane.io/v1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-2><a class=lnlinks href=#hl-0-2> 2</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>XBuckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-3><a class=lnlinks href=#hl-0-3> 3</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-4><a class=lnlinks href=#hl-0-4> 4</a></span><span class=cl><span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-5><a class=lnlinks href=#hl-0-5> 5</a></span><span class=cl><span class=w></span><span class=nt>spec</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-6><a class=lnlinks href=#hl-0-6> 6</a></span><span class=cl><span class=w> </span><span class=nt>region</span><span class=p>:</span><span class=w> </span><span class=l>us-east-2</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-7><a class=lnlinks href=#hl-0-7> 7</a></span><span class=cl><span class=w> </span><span class=nt>names</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-8><a class=lnlinks href=#hl-0-8> 8</a></span><span class=cl><span class=w> </span>- <span class=l>crossplane-functions-example-a</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-9><a class=lnlinks href=#hl-0-9> 9</a></span><span class=cl><span class=w> </span>- <span class=l>crossplane-functions-example-b</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-0-10><a class=lnlinks href=#hl-0-10>10</a></span><span class=cl><span class=w> </span>- <span class=l>crossplane-functions-example-c</span><span class=w> </span></span></span></code></pre></div><br><p>The <code>composition.yaml</code> file contains the Composition to use to render the composite resource:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-yaml data-lang=yaml><span class=line><span class=ln id=hl-1-1><a class=lnlinks href=#hl-1-1> 1</a></span><span class=cl><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>apiextensions.crossplane.io/v1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-2><a class=lnlinks href=#hl-1-2> 2</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>Composition</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-3><a class=lnlinks href=#hl-1-3> 3</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-4><a class=lnlinks href=#hl-1-4> 4</a></span><span class=cl><span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class=l>create-buckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-5><a class=lnlinks href=#hl-1-5> 5</a></span><span class=cl><span class=w></span><span class=nt>spec</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-6><a class=lnlinks href=#hl-1-6> 6</a></span><span class=cl><span class=w> </span><span class=nt>compositeTypeRef</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-7><a class=lnlinks href=#hl-1-7> 7</a></span><span class=cl><span class=w> </span><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>example.crossplane.io/v1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-8><a class=lnlinks href=#hl-1-8> 8</a></span><span class=cl><span class=w> </span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>XBuckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-9><a class=lnlinks href=#hl-1-9> 9</a></span><span class=cl><span class=w> </span><span class=nt>mode</span><span class=p>:</span><span class=w> </span><span class=l>Pipeline</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-10><a class=lnlinks href=#hl-1-10>10</a></span><span class=cl><span class=w> </span><span class=nt>pipeline</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-11><a class=lnlinks href=#hl-1-11>11</a></span><span class=cl><span class=w> </span>- <span class=nt>step</span><span class=p>:</span><span class=w> </span><span class=l>create-buckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-12><a class=lnlinks href=#hl-1-12>12</a></span><span class=cl><span class=w> </span><span class=nt>functionRef</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-1-13><a class=lnlinks href=#hl-1-13>13</a></span><span class=cl><span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class=l>function-xbuckets</span><span class=w> </span></span></span></code></pre></div><br><p>The <code>functions.yaml</code> file contains the Functions the Composition references in its pipeline steps:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-yaml data-lang=yaml><span class=line><span class=ln id=hl-2-1><a class=lnlinks href=#hl-2-1> 1</a></span><span class=cl><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>pkg.crossplane.io/v1beta1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-2><a class=lnlinks href=#hl-2-2> 2</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>Function</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-3><a class=lnlinks href=#hl-2-3> 3</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-4><a class=lnlinks href=#hl-2-4> 4</a></span><span class=cl><span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class=l>function-xbuckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-5><a class=lnlinks href=#hl-2-5> 5</a></span><span class=cl><span class=w> </span><span class=nt>annotations</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-6><a class=lnlinks href=#hl-2-6> 6</a></span><span class=cl><span class=w> </span><span class=nt>render.crossplane.io/runtime</span><span class=p>:</span><span class=w> </span><span class=l>Development</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-7><a class=lnlinks href=#hl-2-7> 7</a></span><span class=cl><span class=w></span><span class=nt>spec</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-8><a class=lnlinks href=#hl-2-8> 8</a></span><span class=cl><span class=w> </span><span class=c># The CLI ignores this package when using the Development runtime.</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-9><a class=lnlinks href=#hl-2-9> 9</a></span><span class=cl><span class=w> </span><span class=c># You can set it to any value.</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-2-10><a class=lnlinks href=#hl-2-10>10</a></span><span class=cl><span class=w> </span><span class=nt>package</span><span class=p>:</span><span class=w> </span><span class=l>xpkg.upbound.io/negz/function-xbuckets:v0.1.0</span><span class=w> </span></span></span></code></pre></div></div></div></div></div><p>The Function in <code>functions.yaml</code> uses the <code><highlight-term id=1731573034480140172 data-label=development data-line=6>Development</highlight-term></code> runtime. This tells <code>crossplane beta render</code> that your function is running locally. It connects to your locally running function instead of using Docker to pull and run the function.</p><div class=highlight label=development><pre tabindex=0 class=chroma><code class=language-yaml data-lang=yaml><span class=line><span class=ln id=hl-7-1><a class=lnlinks href=#hl-7-1>1</a></span><span class=cl><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>pkg.crossplane.io/v1beta1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-7-2><a class=lnlinks href=#hl-7-2>2</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>Function</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-7-3><a class=lnlinks href=#hl-7-3>3</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-7-4><a class=lnlinks href=#hl-7-4>4</a></span><span class=cl><span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class=l>function-xbuckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-7-5><a class=lnlinks href=#hl-7-5>5</a></span><span class=cl><span class=w> </span><span class=nt>annotations</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-7-6><a class=lnlinks href=#hl-7-6>6</a></span><span class=cl><span class=w> </span><span class=nt>render.crossplane.io/runtime</span><span class=p>:</span><span class=w> </span><span class=l>Development</span><span class=w> </span></span></span></code></pre></div><p>Use <code>go run</code> to run your function locally.</p><div class=highlight label=run><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-8-1><a class=lnlinks href=#hl-8-1>1</a></span><span class=cl>go run . --insecure --debug </span></span></code></pre></div><div class="admonition warning d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="warning:"><use xlink:href="#fire"/></svg><span class=ps-1>Warning</span></div><div class=admonition-content>The <code><highlight-term id=1731573034480164854 data-label=run data-line=1>insecure</highlight-term></code> flag tells the function to run without encryption or authentication. Only use it during testing and development.</div></div><p>In a separate terminal, run <code>crossplane beta render</code>.</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-9-1><a class=lnlinks href=#hl-9-1>1</a></span><span class=cl>crossplane beta render xr.yaml composition.yaml functions.yaml </span></span></code></pre></div><p>This command calls your function. In the terminal where your function is running you should now see log output:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-10-1><a class=lnlinks href=#hl-10-1>1</a></span><span class=cl>go run . --insecure --debug </span></span><span class=line><span class=ln id=hl-10-2><a class=lnlinks href=#hl-10-2>2</a></span><span class=cl>2023-10-31T16:17:32.158-0700 INFO <span class=k>function</span>-xbuckets/fn.go:29 Running Function <span class=o>{</span><span class=s2>"tag"</span>: <span class=s2>""</span><span class=o>}</span> </span></span><span class=line><span class=ln id=hl-10-3><a class=lnlinks href=#hl-10-3>3</a></span><span class=cl>2023-10-31T16:17:32.159-0700 INFO <span class=k>function</span>-xbuckets/fn.go:125 Added desired buckets <span class=o>{</span><span class=s2>"xr-version"</span>: <span class=s2>"example.crossplane.io/v1"</span>, <span class=s2>"xr-kind"</span>: <span class=s2>"XBuckets"</span>, <span class=s2>"xr-name"</span>: <span class=s2>"example-buckets"</span>, <span class=s2>"region"</span>: <span class=s2>"us-east-2"</span>, <span class=s2>"count"</span>: 3<span class=o>}</span> </span></span></code></pre></div><p>The <code>crossplane beta render</code> command prints the desired resources the function returns.</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-yaml data-lang=yaml><span class=line><span class=ln id=hl-11-1><a class=lnlinks href=#hl-11-1> 1</a></span><span class=cl><span class=nn>---</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-2><a class=lnlinks href=#hl-11-2> 2</a></span><span class=cl><span class=w></span><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>example.crossplane.io/v1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-3><a class=lnlinks href=#hl-11-3> 3</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>XBuckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-4><a class=lnlinks href=#hl-11-4> 4</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-5><a class=lnlinks href=#hl-11-5> 5</a></span><span class=cl><span class=w> </span><span class=nt>name</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-6><a class=lnlinks href=#hl-11-6> 6</a></span><span class=cl><span class=w></span><span class=nn>---</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-7><a class=lnlinks href=#hl-11-7> 7</a></span><span class=cl><span class=w></span><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>s3.aws.upbound.io/v1beta1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-8><a class=lnlinks href=#hl-11-8> 8</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>Bucket</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-9><a class=lnlinks href=#hl-11-9> 9</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-10><a class=lnlinks href=#hl-11-10>10</a></span><span class=cl><span class=w> </span><span class=nt>annotations</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-11><a class=lnlinks href=#hl-11-11>11</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/composition-resource-name</span><span class=p>:</span><span class=w> </span><span class=l>xbuckets-crossplane-functions-example-b</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-12><a class=lnlinks href=#hl-11-12>12</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/external-name</span><span class=p>:</span><span class=w> </span><span class=l>crossplane-functions-example-b</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-13><a class=lnlinks href=#hl-11-13>13</a></span><span class=cl><span class=w> </span><span class=nt>generateName</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets-</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-14><a class=lnlinks href=#hl-11-14>14</a></span><span class=cl><span class=w> </span><span class=nt>labels</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-15><a class=lnlinks href=#hl-11-15>15</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/composite</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-16><a class=lnlinks href=#hl-11-16>16</a></span><span class=cl><span class=w> </span><span class=nt>ownerReferences</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-17><a class=lnlinks href=#hl-11-17>17</a></span><span class=cl><span class=w> </span><span class=c># Omitted for brevity</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-18><a class=lnlinks href=#hl-11-18>18</a></span><span class=cl><span class=w></span><span class=nt>spec</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-19><a class=lnlinks href=#hl-11-19>19</a></span><span class=cl><span class=w> </span><span class=nt>forProvider</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-20><a class=lnlinks href=#hl-11-20>20</a></span><span class=cl><span class=w> </span><span class=nt>region</span><span class=p>:</span><span class=w> </span><span class=l>us-east-2</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-21><a class=lnlinks href=#hl-11-21>21</a></span><span class=cl><span class=w></span><span class=nn>---</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-22><a class=lnlinks href=#hl-11-22>22</a></span><span class=cl><span class=w></span><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>s3.aws.upbound.io/v1beta1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-23><a class=lnlinks href=#hl-11-23>23</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>Bucket</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-24><a class=lnlinks href=#hl-11-24>24</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-25><a class=lnlinks href=#hl-11-25>25</a></span><span class=cl><span class=w> </span><span class=nt>annotations</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-26><a class=lnlinks href=#hl-11-26>26</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/composition-resource-name</span><span class=p>:</span><span class=w> </span><span class=l>xbuckets-crossplane-functions-example-c</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-27><a class=lnlinks href=#hl-11-27>27</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/external-name</span><span class=p>:</span><span class=w> </span><span class=l>crossplane-functions-example-c</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-28><a class=lnlinks href=#hl-11-28>28</a></span><span class=cl><span class=w> </span><span class=nt>generateName</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets-</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-29><a class=lnlinks href=#hl-11-29>29</a></span><span class=cl><span class=w> </span><span class=nt>labels</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-30><a class=lnlinks href=#hl-11-30>30</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/composite</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-31><a class=lnlinks href=#hl-11-31>31</a></span><span class=cl><span class=w> </span><span class=nt>ownerReferences</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-32><a class=lnlinks href=#hl-11-32>32</a></span><span class=cl><span class=w> </span><span class=c># Omitted for brevity</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-33><a class=lnlinks href=#hl-11-33>33</a></span><span class=cl><span class=w></span><span class=nt>spec</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-34><a class=lnlinks href=#hl-11-34>34</a></span><span class=cl><span class=w> </span><span class=nt>forProvider</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-35><a class=lnlinks href=#hl-11-35>35</a></span><span class=cl><span class=w> </span><span class=nt>region</span><span class=p>:</span><span class=w> </span><span class=l>us-east-2</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-36><a class=lnlinks href=#hl-11-36>36</a></span><span class=cl><span class=w></span><span class=nn>---</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-37><a class=lnlinks href=#hl-11-37>37</a></span><span class=cl><span class=w></span><span class=nt>apiVersion</span><span class=p>:</span><span class=w> </span><span class=l>s3.aws.upbound.io/v1beta1</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-38><a class=lnlinks href=#hl-11-38>38</a></span><span class=cl><span class=w></span><span class=nt>kind</span><span class=p>:</span><span class=w> </span><span class=l>Bucket</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-39><a class=lnlinks href=#hl-11-39>39</a></span><span class=cl><span class=w></span><span class=nt>metadata</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-40><a class=lnlinks href=#hl-11-40>40</a></span><span class=cl><span class=w> </span><span class=nt>annotations</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-41><a class=lnlinks href=#hl-11-41>41</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/composition-resource-name</span><span class=p>:</span><span class=w> </span><span class=l>xbuckets-crossplane-functions-example-a</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-42><a class=lnlinks href=#hl-11-42>42</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/external-name</span><span class=p>:</span><span class=w> </span><span class=l>crossplane-functions-example-a</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-43><a class=lnlinks href=#hl-11-43>43</a></span><span class=cl><span class=w> </span><span class=nt>generateName</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets-</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-44><a class=lnlinks href=#hl-11-44>44</a></span><span class=cl><span class=w> </span><span class=nt>labels</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-45><a class=lnlinks href=#hl-11-45>45</a></span><span class=cl><span class=w> </span><span class=nt>crossplane.io/composite</span><span class=p>:</span><span class=w> </span><span class=l>example-buckets</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-46><a class=lnlinks href=#hl-11-46>46</a></span><span class=cl><span class=w> </span><span class=nt>ownerReferences</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-47><a class=lnlinks href=#hl-11-47>47</a></span><span class=cl><span class=w> </span><span class=c># Omitted for brevity</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-48><a class=lnlinks href=#hl-11-48>48</a></span><span class=cl><span class=w></span><span class=nt>spec</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-49><a class=lnlinks href=#hl-11-49>49</a></span><span class=cl><span class=w> </span><span class=nt>forProvider</span><span class=p>:</span><span class=w> </span></span></span><span class=line><span class=ln id=hl-11-50><a class=lnlinks href=#hl-11-50>50</a></span><span class=cl><span class=w> </span><span class=nt>region</span><span class=p>:</span><span class=w> </span><span class=l>us-east-2</span><span class=w> </span></span></span></code></pre></div><div class="admonition tip d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="tip:"><use xlink:href="#check"/></svg><span class=ps-1>Tip</span></div><div class=admonition-content>Read the composition functions documentation to learn more about <a href=https://docs.crossplane.io/v1.16/concepts/composition-functions/#test-a-composition-that-uses-functions>testing composition functions</a>.</div></div><h2 id=build-and-push-the-function-to-a-package-registry>Build and push the function to a package registry <a class=anchor-link id=build-and-push-the-function-to-a-package-registry href=#build-and-push-the-function-to-a-package-registry aria-label="Link to this section: Build and push the function to a package registry"></a></h2><p>You build a function in two stages. First you build the function’s runtime. This is the Open Container Initiative (OCI) image Crossplane uses to run your function. You then embed that runtime in a package, and push it to a package registry. The Crossplane CLI uses <code>xpkg.upbound.io</code> as its default package registry.</p><p>A function supports a single platform, like <code>linux/amd64</code>, by default. You can support multiple platforms by building a runtime and package for each platform, then pushing all the packages to a single tag in the registry.</p><p>Pushing your function to a registry allows you to use your function in a Crossplane control plane. See the <a href=https://docs.crossplane.io/v1.16/concepts/composition-functions/>composition functions documentation</a>. to learn how to use a function in a control plane.</p><p>Use Docker to build a runtime for each platform.</p><div class=highlight copy-lines=1><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-12-1><a class=lnlinks href=#hl-12-1>1</a></span><span class=cl>docker build . --quiet --platform<span class=o>=</span>linux/amd64 --tag runtime-amd64 </span></span><span class=line><span class=ln id=hl-12-2><a class=lnlinks href=#hl-12-2>2</a></span><span class=cl>sha256:fdf40374cc6f0b46191499fbc1dbbb05ddb76aca854f69f2912e580cfe624b4b </span></span></code></pre></div><div class=highlight copy-lines=1><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-13-1><a class=lnlinks href=#hl-13-1>1</a></span><span class=cl>docker build . --quiet --platform<span class=o>=</span>linux/arm64 --tag runtime-arm64 </span></span><span class=line><span class=ln id=hl-13-2><a class=lnlinks href=#hl-13-2>2</a></span><span class=cl>sha256:cb015ceabf46d2a55ccaeebb11db5659a2fb5e93de36713364efcf6d699069af </span></span></code></pre></div><div class="admonition tip d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="tip:"><use xlink:href="#check"/></svg><span class=ps-1>Tip</span></div><div class=admonition-content>You can use whatever tag you want. There’s no need to push the runtime images to a registry. The tag is only used to tell <code>crossplane xpkg build</code> what runtime to embed.</div></div><p>Use the Crossplane CLI to build a package for each platform. Each package embeds a runtime image.</p><p>The <code><highlight-term id=1731573034480364562 data-label=build data-line=2>--package-root</highlight-term></code> flag specifies the <code>package</code> directory, which contains <code>crossplane.yaml</code>. This includes metadata about the package.</p><p>The <code><highlight-term id=1731573034480381425 data-label=build data-line=3>--embed-runtime-image</highlight-term></code> flag specifies the runtime image tag built using Docker.</p><p>The <code><highlight-term id=1731573034480397722 data-label=build data-line=4>--package-file</highlight-term></code> flag specifies specifies where to write the package file to disk. Crossplane package files use the extension <code>.xpkg</code>.</p><div class=highlight label=build><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-14-1><a class=lnlinks href=#hl-14-1>1</a></span><span class=cl>crossplane xpkg build <span class=se>\ </span></span></span><span class=line><span class=ln id=hl-14-2><a class=lnlinks href=#hl-14-2>2</a></span><span class=cl><span class=se></span> --package-root<span class=o>=</span>package <span class=se>\ </span></span></span><span class=line><span class=ln id=hl-14-3><a class=lnlinks href=#hl-14-3>3</a></span><span class=cl><span class=se></span> --embed-runtime-image<span class=o>=</span>runtime-amd64 <span class=se>\ </span></span></span><span class=line><span class=ln id=hl-14-4><a class=lnlinks href=#hl-14-4>4</a></span><span class=cl><span class=se></span> --package-file<span class=o>=</span><span class=k>function</span>-amd64.xpkg </span></span></code></pre></div><div class=highlight><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-15-1><a class=lnlinks href=#hl-15-1>1</a></span><span class=cl>crossplane xpkg build <span class=se>\ </span></span></span><span class=line><span class=ln id=hl-15-2><a class=lnlinks href=#hl-15-2>2</a></span><span class=cl><span class=se></span> --package-root<span class=o>=</span>package <span class=se>\ </span></span></span><span class=line><span class=ln id=hl-15-3><a class=lnlinks href=#hl-15-3>3</a></span><span class=cl><span class=se></span> --embed-runtime-image<span class=o>=</span>runtime-arm64 <span class=se>\ </span></span></span><span class=line><span class=ln id=hl-15-4><a class=lnlinks href=#hl-15-4>4</a></span><span class=cl><span class=se></span> --package-file<span class=o>=</span><span class=k>function</span>-arm64.xpkg </span></span></code></pre></div><div class="admonition tip d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="tip:"><use xlink:href="#check"/></svg><span class=ps-1>Tip</span></div><div class=admonition-content>Crossplane packages are special OCI images. Read more about packages in the <a href=https://docs.crossplane.io/v1.16/concepts/packages/>packages documentation</a>.</div></div><p>Push both package files to a registry. Pushing both files to one tag in the registry creates a <a href=https://docs.docker.com/build/building/multi-platform/>multi-platform</a> package that runs on both <code>linux/arm64</code> and <code>linux/amd64</code> hosts.</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-shell data-lang=shell><span class=line><span class=ln id=hl-16-1><a class=lnlinks href=#hl-16-1>1</a></span><span class=cl>crossplane xpkg push <span class=se>\ </span></span></span><span class=line><span class=ln id=hl-16-2><a class=lnlinks href=#hl-16-2>2</a></span><span class=cl><span class=se></span> --package-files<span class=o>=</span><span class=k>function</span>-amd64.xpkg,function-arm64.xpkg <span class=se>\ </span></span></span><span class=line><span class=ln id=hl-16-3><a class=lnlinks href=#hl-16-3>3</a></span><span class=cl><span class=se></span> negz/function-xbuckets:v0.1.0 </span></span></code></pre></div><div class="admonition tip d-flex flex-column mx-4 p-0"><div class=admonition-title><svg class="bi flex-shrink-0" role="img" aria-label="tip:"><use xlink:href="#check"/></svg><span class=ps-1>Tip</span></div><div class=admonition-content><p>If you push the function to a GitHub repository the template automatically sets up continuous integration (CI) using <a href=https://github.com/features/actions>GitHub Actions</a>. The CI workflow will lint, test, and build your function. You can see how the template configures CI by reading <code>.github/workflows/ci.yaml</code>.</p><p>The CI workflow can automatically push packages to <code>xpkg.upbound.io</code>. For this to work you must create a repository at <a href=https://marketplace.upbound.io>https://marketplace.upbound.io</a>. Give the CI workflow access to push to the Marketplace by creating an API token and <a href=https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository>adding it to your repository</a>. Save your API token access ID as a secret named <code>XPKG_ACCESS_ID</code> and your API token as a secret named <code>XPKG_TOKEN</code>.</p></div></div></div></main></div><footer class="bd-footer p-5"><div class="container text-center"><div class="row pb-5 top-row"><div class="col-lg img-col"><img src=/img/crossplane-logo.svg alt="Crossplane logo" srcset="/img/crossplane-logo.svg 1x, /img/crossplane-logo.svg 2x" width=185 height=40 decoding=async data-nimg=future loading=lazy class="d-flex crossplane-footer"></div><div class="col-lg links-col d-fill justify-content-evenly ms-5"><div class=row><div class=col-lg><a class=footer-link target=_blank href=https://twitter.com/crossplane_io>Twitter</a></div><div class=col-lg><a class=footer-link target=_blank href=https://www.youtube.com/channel/UC19FgzMBMqBro361HbE46Fw>Youtube</a></div><div class=col-lg><a class=footer-link target=_blank href="https://www.youtube.com/playlist?list=PL510POnNVaaYFuK-B_SIUrpIonCtLVOzT">Podcast</a></div><div class=col-lg><a class=footer-link target=_blank href=https://groups.google.com/g/crossplane-dev>Forum</a></div></div></div></div><div class="row pb-5"><div class="col-lg copyright-col pe-4 border-end"><p>© Crossplane Authors 2024. Documentation distributed under <a target=_blank href=https://creativecommons.org/licenses/by/4.0/>CC-BY-4.0</a>.</p><p>© 2024 The Linux Foundation. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our <a target=_blank href=https://www.linuxfoundation.org/legal/trademark-usage>Trademark Usage</a> page.</p></div><div class="col-lg cncf-col ms-5"><a class=d-flex target=_blank href=https://www.cncf.io/><img alt=cncfLogo src=/img/cncf-white.webp width=702 height=114 decoding=async data-nimg=future loading=lazy class="cncf-footer py-3"></a><p class=d-flex>We are a Cloud Native Computing Foundation incubating project.</p></div></div></div></footer><script src=https://docs.crossplane.io/js/main-727bf178.bundle.min.js data-no-instant></script><script type=text/javascript>(function(e,t,n,s,o,i,a){e[n]=e[n]||function(){(e[n].q=e[n].q||[]).push(arguments)},i=t.createElement(s),i.async=1,i.src="https://www.clarity.ms/tag/"+o,a=t.getElementsByTagName(s)[0],a.parentNode.insertBefore(i,a)})(window,document,"clarity","script","el5517lxor")</script> <script>(function(e,t,n,s,o){e[s]=e[s]||[],e[s].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var a=t.getElementsByTagName(n)[0],i=t.createElement(n),r=s!="dataLayer"?"&l="+s:"";i.async=!0,i.src="https://www.googletagmanager.com/gtm.js?id="+o+r,a.parentNode.insertBefore(i,a)})(window,document,"script","dataLayer","GTM-WFF2NQHG")</script><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WFF2NQHG" height=0 width=0 style=display:none;visibility:hidden></iframe></noscript><script type=text/javascript>adroll_adv_id="B4XQTO44VJFVDGCGM332GU",adroll_pix_id="6ROIBHUPMVCSXN7HHIKJTK",adroll_version="2.0",function(e,t,n,s,o){e.__adroll_loaded=!0,e.adroll=e.adroll||[],e.adroll.f=["setProperties","identify","track"];var i="https://s.adroll.com/j/"+adroll_adv_id+"/roundtrip.js";for(o=0;o<e.adroll.f.length;o++)e.adroll[e.adroll.f[o]]=e.adroll[e.adroll.f[o]]||function(t){return function(){e.adroll.push([t,arguments])}}(e.adroll.f[o]);n=t.createElement("script"),s=t.getElementsByTagName("script")[0],n.async=1,n.src=i,s.parentNode.insertBefore(n,s)}(window,document),adroll.track("pageView")</script><script src=https://cdn.jsdelivr.net/npm/@docsearch/js@3></script> <script>docsearch({container:"#docSearch",appId:"9UXKYX61NK",indexName:"crossplane",apiKey:"e07e181044d561f6a4cb7261931d980a",placeholder:"Search the docs"})</script></body></html>