@@ -787,78 +787,103 @@ func (r *ClusterResource) validateGCPNetworkConfig(ctx context.Context, data *Cl
787
787
// apply applies changes to a cluster. It can be used for both creating and updating a cluster.
788
788
// This implements the core part of the Create and Update methods.
789
789
func (r * ClusterResource ) apply (ctx context.Context , data * ClusterResourceModel , skipInitRPC , skipNodeUpgrade bool ) diag.Diagnostics {
790
+ r .logWithContext (ctx , "INFO" , "Starting cluster apply" , map [string ]interface {}{
791
+ "skipInitRPC" : skipInitRPC ,
792
+ "skipNodeUpgrade" : skipNodeUpgrade ,
793
+ })
794
+
790
795
diags := diag.Diagnostics {}
791
796
792
797
// Parse and convert values from the Terraform state
793
798
// to formats the Constellation library can work with.
799
+ r .logWithContext (ctx , "DEBUG" , "Validating GCP network config" )
794
800
convertDiags := r .validateGCPNetworkConfig (ctx , data )
795
801
diags .Append (convertDiags ... )
796
802
if diags .HasError () {
803
+ r .logWithContext (ctx , "ERROR" , "Failed to validate GCP network config" , map [string ]interface {}{"error" : diags .Errors ()})
797
804
return diags
798
805
}
799
806
800
807
csp := cloudprovider .FromString (data .CSP .ValueString ())
808
+ r .logWithContext (ctx , "DEBUG" , "Parsed CSP" , map [string ]interface {}{"csp" : csp .String ()})
801
809
802
810
// parse attestation config
811
+ r .logWithContext (ctx , "DEBUG" , "Converting attestation config" )
803
812
att , convertDiags := r .convertAttestationConfig (ctx , * data )
804
813
diags .Append (convertDiags ... )
805
814
if diags .HasError () {
815
+ r .logWithContext (ctx , "ERROR" , "Failed to convert attestation config" , map [string ]interface {}{"error" : diags .Errors ()})
806
816
return diags
807
817
}
808
818
809
819
// parse secrets (i.e. measurement salt, master secret, etc.)
820
+ r .logWithContext (ctx , "DEBUG" , "Converting secrets" )
810
821
secrets , convertDiags := r .convertSecrets (* data )
811
822
diags .Append (convertDiags ... )
812
823
if diags .HasError () {
824
+ r .logWithContext (ctx , "ERROR" , "Failed to convert secrets" , map [string ]interface {}{"error" : diags .Errors ()})
813
825
return diags
814
826
}
815
827
816
828
// parse API server certificate SANs
829
+ r .logWithContext (ctx , "DEBUG" , "Getting API server cert SANs" )
817
830
apiServerCertSANs , convertDiags := r .getAPIServerCertSANs (ctx , data )
818
831
diags .Append (convertDiags ... )
819
832
if diags .HasError () {
833
+ r .logWithContext (ctx , "ERROR" , "Failed to get API server cert SANs" , map [string ]interface {}{"error" : diags .Errors ()})
820
834
return diags
821
835
}
822
836
823
837
// parse network config
838
+ r .logWithContext (ctx , "DEBUG" , "Getting network config" )
824
839
networkCfg , getDiags := r .getNetworkConfig (ctx , data )
825
840
diags .Append (getDiags ... )
826
841
if diags .HasError () {
842
+ r .logWithContext (ctx , "ERROR" , "Failed to get network config" , map [string ]interface {}{"error" : diags .Errors ()})
827
843
return diags
828
844
}
829
845
830
846
// parse Constellation microservice config
847
+ r .logWithContext (ctx , "DEBUG" , "Parsing microservice config" )
831
848
var microserviceCfg extraMicroservicesAttribute
832
849
convertDiags = data .ExtraMicroservices .As (ctx , & microserviceCfg , basetypes.ObjectAsOptions {
833
850
UnhandledNullAsEmpty : true , // we want to allow null values, as the CSIDriver field is optional
834
851
})
835
852
diags .Append (convertDiags ... )
836
853
if diags .HasError () {
854
+ r .logWithContext (ctx , "ERROR" , "Failed to parse microservice config" , map [string ]interface {}{"error" : diags .Errors ()})
837
855
return diags
838
856
}
839
857
840
858
// parse Constellation microservice version
859
+ r .logWithContext (ctx , "DEBUG" , "Getting microservice version" )
841
860
microserviceVersion , convertDiags := r .getMicroserviceVersion (data )
842
861
diags .Append (convertDiags ... )
843
862
if diags .HasError () {
863
+ r .logWithContext (ctx , "ERROR" , "Failed to get microservice version" , map [string ]interface {}{"error" : diags .Errors ()})
844
864
return diags
845
865
}
846
866
847
867
// parse Kubernetes version
868
+ r .logWithContext (ctx , "DEBUG" , "Getting Kubernetes version" )
848
869
k8sVersion , getDiags := r .getK8sVersion (data )
849
870
diags .Append (getDiags ... )
850
871
if diags .HasError () {
872
+ r .logWithContext (ctx , "ERROR" , "Failed to get Kubernetes version" , map [string ]interface {}{"error" : diags .Errors ()})
851
873
return diags
852
874
}
853
875
854
876
// parse OS image version
877
+ r .logWithContext (ctx , "DEBUG" , "Getting OS image version" )
855
878
image , imageSemver , convertDiags := r .getImageVersion (ctx , data )
856
879
diags .Append (convertDiags ... )
857
880
if diags .HasError () {
881
+ r .logWithContext (ctx , "ERROR" , "Failed to get OS image version" , map [string ]interface {}{"error" : diags .Errors ()})
858
882
return diags
859
883
}
860
884
861
885
// parse license ID
886
+ r .logWithContext (ctx , "DEBUG" , "Parsing license ID" )
862
887
licenseID := data .LicenseID .ValueString ()
863
888
switch {
864
889
case image .MarketplaceImage != nil && * image .MarketplaceImage :
@@ -874,6 +899,7 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
874
899
}
875
900
876
901
// Parse in-cluster service account info.
902
+ r .logWithContext (ctx , "DEBUG" , "Parsing service account info" )
877
903
serviceAccPayload := constellation.ServiceAccountPayload {}
878
904
var gcpConfig gcpAttribute
879
905
var azureConfig azureAttribute
@@ -883,6 +909,7 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
883
909
convertDiags = data .GCP .As (ctx , & gcpConfig , basetypes.ObjectAsOptions {})
884
910
diags .Append (convertDiags ... )
885
911
if diags .HasError () {
912
+ r .logWithContext (ctx , "ERROR" , "Failed to parse GCP config" , map [string ]interface {}{"error" : diags .Errors ()})
886
913
return diags
887
914
}
888
915
@@ -906,6 +933,7 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
906
933
convertDiags = data .Azure .As (ctx , & azureConfig , basetypes.ObjectAsOptions {})
907
934
diags .Append (convertDiags ... )
908
935
if diags .HasError () {
936
+ r .logWithContext (ctx , "ERROR" , "Failed to parse Azure config" , map [string ]interface {}{"error" : diags .Errors ()})
909
937
return diags
910
938
}
911
939
serviceAccPayload .Azure = azureshared.ApplicationCredentials {
@@ -918,6 +946,7 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
918
946
convertDiags = data .OpenStack .As (ctx , & openStackConfig , basetypes.ObjectAsOptions {})
919
947
diags .Append (convertDiags ... )
920
948
if diags .HasError () {
949
+ r .logWithContext (ctx , "ERROR" , "Failed to parse OpenStack config" , map [string ]interface {}{"error" : diags .Errors ()})
921
950
return diags
922
951
}
923
952
cloudsYAML , err := clouds .ReadCloudsYAML (file .NewHandler (afero .NewOsFs ()), openStackConfig .CloudsYAMLPath )
@@ -942,8 +971,11 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
942
971
}
943
972
944
973
}
974
+
975
+ r .logWithContext (ctx , "DEBUG" , "Marshalling service account URI" )
945
976
serviceAccURI , err := constellation .MarshalServiceAccountURI (csp , serviceAccPayload )
946
977
if err != nil {
978
+ r .logWithContext (ctx , "ERROR" , "Failed to marshal service account URI" , map [string ]interface {}{"error" : err .Error ()})
947
979
diags .AddError ("Marshalling service account URI" , err .Error ())
948
980
return diags
949
981
}
@@ -955,14 +987,17 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
955
987
}
956
988
957
989
// setup clients
990
+ r .logWithContext (ctx , "DEBUG" , "Setting up clients" )
958
991
validator , err := choose .Validator (att .config , & tfContextLogger {ctx : ctx })
959
992
if err != nil {
993
+ r .logWithContext (ctx , "ERROR" , "Failed to choose validator" , map [string ]interface {}{"error" : err .Error ()})
960
994
diags .AddError ("Choosing validator" , err .Error ())
961
995
return diags
962
996
}
963
997
applier := r .newApplier (ctx , validator )
964
998
965
999
// Construct in-memory state file
1000
+ r .logWithContext (ctx , "DEBUG" , "Constructing in-memory state file" )
966
1001
stateFile := state .New ().SetInfrastructure (state.Infrastructure {
967
1002
UID : data .UID .ValueString (),
968
1003
ClusterEndpoint : data .OutOfClusterEndpoint .ValueString (),
@@ -995,21 +1030,24 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
995
1030
}
996
1031
997
1032
// Check license
1033
+ r .logWithContext (ctx , "DEBUG" , "Checking license" )
998
1034
quota , err := applier .CheckLicense (ctx , csp , ! skipInitRPC , licenseID )
999
1035
if err != nil {
1036
+ r .logWithContext (ctx , "WARN" , "Unable to contact license server" , map [string ]interface {}{"error" : err .Error ()})
1000
1037
diags .AddWarning ("Unable to contact license server." , "Please keep your vCPU quota in mind." )
1001
1038
} else if licenseID == license .CommunityLicense {
1039
+ r .logWithContext (ctx , "WARN" , "Using community license" )
1002
1040
diags .AddWarning ("Using community license." , "For details, see https://docs.edgeless.systems/constellation/overview/license" )
1003
1041
} else {
1004
- tflog . Info (ctx , fmt . Sprintf ( "Please keep your vCPU quota (%d) in mind. " , quota ) )
1042
+ r . logWithContext (ctx , "INFO" , "License check completed " , map [ string ] interface {}{ "vCPU_quota" : quota } )
1005
1043
}
1006
1044
1007
1045
// Now, we perform the actual applying.
1008
1046
1009
1047
// Run init RPC
1010
- var initDiags diag.Diagnostics
1011
1048
if ! skipInitRPC {
1012
1049
// run the init RPC and retrieve the post-init state
1050
+ r .logWithContext (ctx , "INFO" , "Running init RPC" )
1013
1051
initRPCPayload := initRPCPayload {
1014
1052
csp : csp ,
1015
1053
masterSecret : secrets .masterSecret ,
@@ -1022,16 +1060,18 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
1022
1060
k8sVersion : k8sVersion ,
1023
1061
inClusterEndpoint : inClusterEndpoint ,
1024
1062
}
1025
- initDiags = r .runInitRPC (ctx , applier , initRPCPayload , data , validator , stateFile )
1063
+ initDiags : = r .runInitRPC (ctx , applier , initRPCPayload , data , validator , stateFile )
1026
1064
diags .Append (initDiags ... )
1027
1065
if diags .HasError () {
1066
+ r .logWithContext (ctx , "ERROR" , "Init RPC failed" , map [string ]interface {}{"error" : diags .Errors ()})
1028
1067
return diags
1029
1068
}
1030
1069
}
1031
1070
1032
1071
// Here, we either have the post-init values from the actual init RPC
1033
1072
// or, if performing an upgrade and skipping the init RPC, we have the
1034
1073
// values from the Terraform state.
1074
+ r .logWithContext (ctx , "DEBUG" , "Setting cluster values" )
1035
1075
stateFile .SetClusterValues (state.ClusterValues {
1036
1076
ClusterID : data .ClusterID .ValueString (),
1037
1077
OwnerID : data .OwnerID .ValueString (),
@@ -1040,25 +1080,32 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
1040
1080
1041
1081
// Kubeconfig is in the state by now. Either through the init RPC or through
1042
1082
// already being in the state.
1083
+ r .logWithContext (ctx , "DEBUG" , "Setting kubeconfig" )
1043
1084
if err := applier .SetKubeConfig ([]byte (data .KubeConfig .ValueString ())); err != nil {
1085
+ r .logWithContext (ctx , "ERROR" , "Failed to set kubeconfig" , map [string ]interface {}{"error" : err .Error ()})
1044
1086
diags .AddError ("Setting kubeconfig" , err .Error ())
1045
1087
return diags
1046
1088
}
1047
1089
1048
1090
// Apply attestation config
1091
+ r .logWithContext (ctx , "DEBUG" , "Applying attestation config" )
1049
1092
if err := applier .ApplyJoinConfig (ctx , att .config , secrets .measurementSalt ); err != nil {
1093
+ r .logWithContext (ctx , "ERROR" , "Failed to apply attestation config" , map [string ]interface {}{"error" : err .Error ()})
1050
1094
diags .AddError ("Applying attestation config" , err .Error ())
1051
1095
return diags
1052
1096
}
1053
1097
1054
1098
// Extend API Server Certificate SANs
1099
+ r .logWithContext (ctx , "DEBUG" , "Extending API server certificate SANs" )
1055
1100
if err := applier .ExtendClusterConfigCertSANs (ctx , data .OutOfClusterEndpoint .ValueString (),
1056
1101
"" , apiServerCertSANs ); err != nil {
1102
+ r .logWithContext (ctx , "ERROR" , "Failed to extend API server certificate SANs" , map [string ]interface {}{"error" : err .Error ()})
1057
1103
diags .AddError ("Extending API server certificate SANs" , err .Error ())
1058
1104
return diags
1059
1105
}
1060
1106
1061
1107
// Apply Helm Charts
1108
+ r .logWithContext (ctx , "INFO" , "Applying Helm charts" )
1062
1109
payload := applyHelmChartsPayload {
1063
1110
csp : cloudprovider .FromString (data .CSP .ValueString ()),
1064
1111
attestationVariant : att .variant ,
@@ -1079,38 +1126,47 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
1079
1126
helmDiags := r .applyHelmCharts (ctx , applier , payload , stateFile )
1080
1127
diags .Append (helmDiags ... )
1081
1128
if diags .HasError () {
1129
+ r .logWithContext (ctx , "ERROR" , "Failed to apply Helm charts" , map [string ]interface {}{"error" : diags .Errors ()})
1082
1130
return diags
1083
1131
}
1084
1132
1085
1133
if ! skipNodeUpgrade {
1086
1134
// Upgrade node image
1135
+ r .logWithContext (ctx , "INFO" , "Upgrading node image" )
1087
1136
err = applier .UpgradeNodeImage (ctx ,
1088
1137
imageSemver ,
1089
1138
image .Reference ,
1090
1139
false )
1091
1140
var upgradeImageErr * compatibility.InvalidUpgradeError
1092
1141
switch {
1093
1142
case errors .Is (err , kubecmd .ErrInProgress ):
1143
+ r .logWithContext (ctx , "WARN" , "Skipping OS image upgrade: Another upgrade is already in progress" )
1094
1144
diags .AddWarning ("Skipping OS image upgrade" , "Another upgrade is already in progress." )
1095
1145
case errors .As (err , & upgradeImageErr ):
1146
+ r .logWithContext (ctx , "WARN" , "Ignoring invalid OS image upgrade" , map [string ]interface {}{"error" : err .Error ()})
1096
1147
diags .AddWarning ("Ignoring invalid OS image upgrade" , err .Error ())
1097
1148
case err != nil :
1149
+ r .logWithContext (ctx , "ERROR" , "Failed to upgrade OS image" , map [string ]interface {}{"error" : err .Error ()})
1098
1150
diags .AddError ("Upgrading OS image" , err .Error ())
1099
1151
return diags
1100
1152
}
1101
1153
1102
1154
// Upgrade Kubernetes components
1155
+ r .logWithContext (ctx , "INFO" , "Upgrading Kubernetes components" )
1103
1156
err = applier .UpgradeKubernetesVersion (ctx , k8sVersion , false )
1104
1157
var upgradeK8sErr * compatibility.InvalidUpgradeError
1105
1158
switch {
1106
1159
case errors .As (err , & upgradeK8sErr ):
1160
+ r .logWithContext (ctx , "WARN" , "Ignoring invalid Kubernetes components upgrade" , map [string ]interface {}{"error" : err .Error ()})
1107
1161
diags .AddWarning ("Ignoring invalid Kubernetes components upgrade" , err .Error ())
1108
1162
case err != nil :
1163
+ r .logWithContext (ctx , "ERROR" , "Failed to upgrade Kubernetes components" , map [string ]interface {}{"error" : err .Error ()})
1109
1164
diags .AddError ("Upgrading Kubernetes components" , err .Error ())
1110
1165
return diags
1111
1166
}
1112
1167
}
1113
1168
1169
+ r .logWithContext (ctx , "INFO" , "Cluster apply completed successfully" )
1114
1170
return diags
1115
1171
}
1116
1172
0 commit comments