@@ -17,13 +17,11 @@ import (
17
17
"io/ioutil"
18
18
corev1 "k8s.io/api/core/v1"
19
19
apierrors "k8s.io/apimachinery/pkg/api/errors"
20
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
20
"k8s.io/apimachinery/pkg/runtime"
22
21
"k8s.io/apimachinery/pkg/types"
23
22
"os"
24
23
"os/exec"
25
24
"path/filepath"
26
- "reflect"
27
25
ctrl "sigs.k8s.io/controller-runtime"
28
26
"sigs.k8s.io/controller-runtime/pkg/client"
29
27
"strings"
@@ -588,118 +586,6 @@ func (r *TerraformRunnerServer) GetInventory(ctx context.Context, req *GetInvent
588
586
return & GetInventoryReply {Inventories : getInventoryFromTerraformModule (state .Values .RootModule )}, nil
589
587
}
590
588
591
- func (r * TerraformRunnerServer ) Output (ctx context.Context , req * OutputRequest ) (* OutputReply , error ) {
592
- log := ctrl .LoggerFrom (ctx , "instance-id" , r .InstanceID ).WithName (loggerName )
593
- log .Info ("creating outputs" )
594
- if req .TfInstance != r .InstanceID {
595
- err := fmt .Errorf ("no TF instance found" )
596
- log .Error (err , "no terraform" )
597
- return nil , err
598
- }
599
-
600
- outputs , err := r .tf .Output (ctx )
601
- if err != nil {
602
- log .Error (err , "unable to get outputs" )
603
- return nil , err
604
- }
605
-
606
- outputReply := & OutputReply {Outputs : map [string ]* OutputMeta {}}
607
- for k , v := range outputs {
608
- outputReply .Outputs [k ] = & OutputMeta {
609
- Sensitive : v .Sensitive ,
610
- Type : v .Type ,
611
- Value : v .Value ,
612
- }
613
- }
614
- return outputReply , nil
615
- }
616
-
617
- func (r * TerraformRunnerServer ) WriteOutputs (ctx context.Context , req * WriteOutputsRequest ) (* WriteOutputsReply , error ) {
618
- log := ctrl .LoggerFrom (ctx , "instance-id" , r .InstanceID ).WithName (loggerName )
619
- log .Info ("write outputs to secret" )
620
-
621
- objectKey := types.NamespacedName {Namespace : req .Namespace , Name : req .SecretName }
622
- var outputSecret corev1.Secret
623
-
624
- drift := true
625
- create := true
626
- if err := r .Client .Get (ctx , objectKey , & outputSecret ); err == nil {
627
- // if everything is there, we don't write anything
628
- if reflect .DeepEqual (outputSecret .Data , req .Data ) {
629
- drift = false
630
- } else {
631
- // found, but need update
632
- create = false
633
- }
634
- } else if apierrors .IsNotFound (err ) == false {
635
- log .Error (err , "unable to get output secret" )
636
- return nil , err
637
- }
638
-
639
- if drift {
640
- if create {
641
- vTrue := true
642
- outputSecret = corev1.Secret {
643
- ObjectMeta : metav1.ObjectMeta {
644
- Name : req .SecretName ,
645
- Namespace : req .Namespace ,
646
- OwnerReferences : []metav1.OwnerReference {
647
- {
648
- APIVersion : infrav1 .GroupVersion .Group + "/" + infrav1 .GroupVersion .Version ,
649
- Kind : infrav1 .TerraformKind ,
650
- Name : req .Name ,
651
- UID : types .UID (req .Uuid ),
652
- Controller : & vTrue ,
653
- },
654
- },
655
- },
656
- Type : corev1 .SecretTypeOpaque ,
657
- Data : req .Data ,
658
- }
659
-
660
- err := r .Client .Create (ctx , & outputSecret )
661
- if err != nil {
662
- log .Error (err , "unable to create secret" )
663
- return nil , err
664
- }
665
- } else {
666
- outputSecret .Data = req .Data
667
- err := r .Client .Update (ctx , & outputSecret )
668
- if err != nil {
669
- log .Error (err , "unable to update secret" )
670
- return nil , err
671
- }
672
- }
673
-
674
- return & WriteOutputsReply {Message : "ok" , Changed : true }, nil
675
- }
676
-
677
- return & WriteOutputsReply {Message : "ok" , Changed : false }, nil
678
- }
679
-
680
- func (r * TerraformRunnerServer ) GetOutputs (ctx context.Context , req * GetOutputsRequest ) (* GetOutputsReply , error ) {
681
- log := ctrl .LoggerFrom (ctx , "instance-id" , r .InstanceID ).WithName (loggerName )
682
- log .Info ("get outputs" )
683
- outputKey := types.NamespacedName {Namespace : req .Namespace , Name : req .SecretName }
684
- outputSecret := corev1.Secret {}
685
- err := r .Client .Get (ctx , outputKey , & outputSecret )
686
- if err != nil {
687
- err = fmt .Errorf ("error getting terraform output for health checks: %s" , err )
688
- log .Error (err , "unable to check terraform health" )
689
- return nil , err
690
- }
691
-
692
- outputs := map [string ]string {}
693
- // parse map[string][]byte to map[string]string for go template parsing
694
- if len (outputSecret .Data ) > 0 {
695
- for k , v := range outputSecret .Data {
696
- outputs [k ] = string (v )
697
- }
698
- }
699
-
700
- return & GetOutputsReply {Outputs : outputs }, nil
701
- }
702
-
703
589
func (r * TerraformRunnerServer ) FinalizeSecrets (ctx context.Context , req * FinalizeSecretsRequest ) (* FinalizeSecretsReply , error ) {
704
590
log := ctrl .LoggerFrom (ctx , "instance-id" , r .InstanceID ).WithName (loggerName )
705
591
log .Info ("finalize the output secrets" )
0 commit comments