@@ -48,40 +48,6 @@ import (
4848 "sigs.k8s.io/controller-runtime/pkg/log"
4949)
5050
51- // CommandExecutor defines an interface for running external commands.
52- type CommandExecutor interface {
53- CombinedOutput () ([]byte , error )
54- SetDir (dir string )
55- }
56-
57- // RealCmdRunner is a concrete implementation of CommandExecutor that runs actual commands.
58- type RealCmdRunner struct {
59- Name string
60- Args []string
61- Dir string
62- CommanderFunc func (command string , args ... string ) ([]byte , error )
63- }
64-
65- func (rcr * RealCmdRunner ) SetDir (dir string ) {
66- rcr .Dir = dir
67- }
68-
69- func (rcr * RealCmdRunner ) CombinedOutput () ([]byte , error ) {
70- if rcr .CommanderFunc != nil {
71- return rcr .CommanderFunc (rcr .Name , rcr .Args ... )
72- }
73- cmd := exec .Command (rcr .Name , rcr .Args ... )
74- if rcr .Dir != "" {
75- cmd .Dir = rcr .Dir
76- }
77-
78- return cmd .CombinedOutput ()
79- }
80-
81- var cmdRunnerFactory = func (name string , args ... string ) CommandExecutor {
82- return & RealCmdRunner {Name : name , Args : args }
83- }
84-
8551func (r * Reconciler ) getCdk8sAppProxyForPolling (ctx context.Context , proxyName types.NamespacedName ) (* addonsv1alpha1.Cdk8sAppProxy , error ) {
8652 cdk8sAppProxy := & addonsv1alpha1.Cdk8sAppProxy {}
8753 if err := r .Get (ctx , proxyName , cdk8sAppProxy ); err != nil {
@@ -137,7 +103,7 @@ func (r *Reconciler) synthesizeAndParseResources(appSourcePath string, logger lo
137103}
138104
139105func (r * Reconciler ) synthesizeCdk8sApp (appSourcePath string , logger logr.Logger , operation string ) error {
140- logger .Info ("Synthesizing cdk8s application" , "effectiveSourcePath" , appSourcePath , "operation" , OperationSynthesize )
106+ logger .Info ("Synthesizing cdk8s application" , "effectiveSourcePath" , appSourcePath , "operation" , operation )
141107
142108 // npmInstall := cmdRunnerFactory("npm", "install")
143109 // npmInstall.SetDir(appSourcePath)
@@ -146,16 +112,15 @@ func (r *Reconciler) synthesizeCdk8sApp(appSourcePath string, logger logr.Logger
146112 // logger.Error(err, "npm installation failed", "output", string(output), "operation:", OperationNpmInstall)
147113 // }
148114
149- synthCmd := cmdRunnerFactory ("cdk8s" , "synth" )
150- synthCmd .SetDir (appSourcePath )
151- output , synthErr := synthCmd .CombinedOutput ()
152- if synthErr != nil {
153- logger .Error (synthErr , "cdk8s synth failed" , "output" , string (output ), "operation" , OperationSynthesize )
115+ synth := exec .Command ("cdk8s" , "synth" )
116+ synth .Dir = appSourcePath
117+ if err := synth .Run (); err != nil {
118+ logger .Error (err , "Failed to synth cdk8s application" , "effectiveSourcePath" , appSourcePath )
154119
155- return synthErr
120+ return err
156121 }
157122
158- logger .Info ("cdk8s synth successful " , "outputSummary " , truncateString ( string ( output ), 200 ) , "operation" , operation )
123+ logger .Info ("Synthesized cdk8s application " , "effectiveSourcePath " , appSourcePath , "operation" , operation )
159124
160125 return nil
161126}
@@ -382,14 +347,6 @@ func (r *Reconciler) updateStatusWithError(ctx context.Context, cdk8sAppProxy *a
382347 return err
383348}
384349
385- func truncateString (str string , num int ) string {
386- if len (str ) > num {
387- return str [0 :num ] + "..."
388- }
389-
390- return str
391- }
392-
393350// TODO: This is a naive pluralization and might not work for all kinds.
394351// A more robust solution would use discovery client or a predefined map.
395352func getPluralFromKind (kind string ) string {
0 commit comments