@@ -710,9 +710,6 @@ func getRestartOpsAgentCmd(imageSpec string) string {
710
710
// PackageLocation describes a location where packages
711
711
// (currently, only the Ops Agent packages) live.
712
712
type PackageLocation struct {
713
- // If provided, a URL for a file in GCS containing a .tar.gz file
714
- // to install on the testing VMs.
715
- uapPluginPackageInGCS string
716
713
// If provided, a URL for a directory in GCS containing .deb/.rpm/.goo files
717
714
// to install on the testing VMs.
718
715
// This setting is mutually exclusive with repoSuffix.
@@ -735,7 +732,6 @@ type PackageLocation struct {
735
732
// LocationFromEnvVars assembles a PackageLocation from environment variables.
736
733
func LocationFromEnvVars () PackageLocation {
737
734
return PackageLocation {
738
- uapPluginPackageInGCS : "gs://ops-agent-uap-plugin/debian12-bookworm/google-cloud-ops-agent-plugin_2.54.0-bookworm-amd64.tar.gz" ,
739
735
packagesInGCS : os .Getenv ("AGENT_PACKAGES_IN_GCS" ),
740
736
repoSuffix : os .Getenv ("REPO_SUFFIX" ),
741
737
repoCodename : os .Getenv ("REPO_CODENAME" ),
@@ -769,13 +765,14 @@ func InstallOpsAgent(ctx context.Context, logger *log.Logger, vm *gce.VM, locati
769
765
if location .packagesInGCS != "" && location .repoSuffix != "" {
770
766
return fmt .Errorf ("invalid PackageLocation: cannot provide both location.packagesInGCS and location.repoSuffix. location=%#v" , location )
771
767
}
772
- if location .uapPluginPackageInGCS != "" {
773
- return InstallOpsAgentUAPPluginFromGCS (ctx , logger , vm , location .uapPluginPackageInGCS )
774
- }
768
+
775
769
if location .artifactRegistryRegion != "" && location .repoSuffix == "" {
776
770
return fmt .Errorf ("invalid PackageLocation: location.artifactRegistryRegion was nonempty yet location.repoSuffix was empty. location=%#v" , location )
777
771
}
778
772
if location .packagesInGCS != "" {
773
+ if IsOpsAgentUAPPlugin () {
774
+ return InstallOpsAgentUAPPluginFromGCS (ctx , logger , vm , location .packagesInGCS )
775
+ }
779
776
return InstallPackageFromGCS (ctx , logger , vm , location .packagesInGCS )
780
777
}
781
778
@@ -945,7 +942,7 @@ func InstallOpsAgentUAPPluginFromGCS(ctx context.Context, logger *log.Logger, vm
945
942
if gce .IsWindows (vm .ImageSpec ) {
946
943
return fmt .Errorf ("Ops Agent UAP Plugin does not support Windows yet" )
947
944
}
948
- if _ , err := gce .RunRemotely (ctx , logger , vm , "mkdir -p /tmp/agentUpload" ); err != nil {
945
+ if _ , err := gce .RunRemotely (ctx , logger , vm , "mkdir -p /tmp/agentUpload /tmp/agentPlugin " ); err != nil {
949
946
return err
950
947
}
951
948
if err := gce .InstallGsutilIfNeeded (ctx , logger , vm ); err != nil {
@@ -954,17 +951,21 @@ func InstallOpsAgentUAPPluginFromGCS(ctx context.Context, logger *log.Logger, vm
954
951
if err := gce .InstallGrpcurlIfNeeded (ctx , logger , vm ); err != nil {
955
952
return err
956
953
}
957
- if _ , err := gce .RunRemotely (ctx , logger , vm , "gsutil cp " + gcsPath + " /tmp/agentUpload" ); err != nil {
954
+
955
+ if _ , err := gce .RunRemotely (ctx , logger , vm , "sudo gsutil cp -r " + gcsPath + "/* /tmp/agentUpload" ); err != nil {
958
956
return fmt .Errorf ("error copying down agent package from GCS: %v" , err )
959
957
}
960
- // Print the contents of /tmp/agentUpload into the logs.
961
- if _ , err := gce .RunRemotely (ctx , logger , vm , "ls -la /tmp/agentUpload" ); err != nil {
958
+ if _ , err := gce .RunRemotely (ctx , logger , vm , "mv /tmp/agentUpload/*.tar.gz /tmp/agentPlugin || echo nothing to move" ); err != nil {
962
959
return err
963
960
}
964
- if _ , err := gce .RunRemotely (ctx , logger , vm , "sudo tar -xzf /tmp/agentUpload/google-cloud-ops-agent-plugin_2.54.0-bookworm-amd64.tar.gz --no-overwrite-dir -C ~/ && ls -la" ); err != nil {
961
+ // Print the contents of /tmp/agentPlugin into the logs.
962
+ if _ , err := gce .RunRemotely (ctx , logger , vm , "ls -la /tmp/agentPlugin" ); err != nil {
965
963
return err
966
964
}
967
- // Print the contents of /tmp/agentUpload into the logs.
965
+ if _ , err := gce .RunRemotely (ctx , logger , vm , "sudo find /tmp/agentPlugin -maxdepth 1 -name \" google-cloud-ops-agent-plugin*.tar.gz\" -print0 | xargs -0 -I {} sudo tar -xzf {} --no-overwrite-dir -C ~/ && ls -la" ); err != nil {
966
+ return err
967
+ }
968
+ // Print the contents of the home dir into the logs.
968
969
if _ , err := gce .RunRemotely (ctx , logger , vm , "ls -la ~/" ); err != nil {
969
970
return err
970
971
}
@@ -1049,5 +1050,7 @@ func GetOtelConfigPath(imageSpec string) string {
1049
1050
}
1050
1051
1051
1052
func IsOpsAgentUAPPlugin () bool {
1052
- return LocationFromEnvVars ().uapPluginPackageInGCS != ""
1053
+ // ok is true when the env variable is preset in the environment.
1054
+ _ , ok := os .LookupEnv ("IS_OPS_AGENT_UAP_PLUGIN" )
1055
+ return ok
1053
1056
}
0 commit comments