Skip to content

Commit

Permalink
Allow VizierID to be used to find the Vizier's org (#1650)
Browse files Browse the repository at this point in the history
Summary: This PR allows the VizierID to be used when getting the org as
opposed to only relying on the DeployKey when adding feature flags.

Relevant Issues: #1632

Type of change: /kind bug

Test Plan: Another PR needs to come in on the operator side to
retrieve/send the VizierID to the cloud. Getting this PR in on the cloud
side will simplify the process of testing the integration between the
two later.

---------

Signed-off-by: Kartik Pattaswamy <[email protected]>
  • Loading branch information
kpattaswamy authored Aug 9, 2023
1 parent b25a3ae commit 1c328aa
Show file tree
Hide file tree
Showing 7 changed files with 563 additions and 408 deletions.
789 changes: 423 additions & 366 deletions src/api/proto/cloudpb/cloudapi.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/api/proto/cloudpb/cloudapi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,8 @@ message ConfigForVizierRequest {
vizierconfigpb.VizierSpec vz_spec = 2;
// Kubernetes version of the cluster Vizier is running on.
string k8s_version = 3 [ (gogoproto.customname) = "K8sVersion" ];
// ID of the Vizier (Cluster ID).
string vizier_id = 4 [ (gogoproto.customname) = "VizierID" ];
}

// ConfigForVizierResponse is the response to a ConfigForVizierRequest.
Expand Down
1 change: 1 addition & 0 deletions src/cloud/api/controllers/config_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (c *ConfigServiceServer) GetConfigForVizier(ctx context.Context,
Registry: vizSpecReq.Registry,
},
K8sVersion: req.K8sVersion,
VizierID: req.VizierID,
})
if err != nil {
return nil, err
Expand Down
22 changes: 21 additions & 1 deletion src/cloud/config_manager/config_manager_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ func newDeploymentKeyClient() (vzmgrpb.VZDeploymentKeyServiceClient, error) {
return vzmgrpb.NewVZDeploymentKeyServiceClient(deployKeyChannel), nil
}

func newVizierManagerClient() (vzmgrpb.VZMgrServiceClient, error) {
dialOpts, err := services.GetGRPCClientDialOpts()
if err != nil {
return nil, err
}

vizierManagerChannel, err := grpc.Dial(viper.GetString("vzmgr_service"), dialOpts...)
if err != nil {
return nil, err
}

return vzmgrpb.NewVZMgrServiceClient(vizierManagerChannel), nil
}

func main() {
services.SetupService("config-manager-service", 50500)
services.PostFlagSetupAndParse()
Expand All @@ -93,7 +107,13 @@ func main() {
if err != nil {
log.WithError(err).Fatal("Could not connect with Artifact Service.")
}
svr := controllers.NewServer(atClient, deployKeyClient, viper.GetString("ld_sdk_key"))

vzmgrClient, err := newVizierManagerClient()
if err != nil {
log.WithError(err).Fatal("Could not connect with VizierManager Service.")
}

svr := controllers.NewServer(atClient, deployKeyClient, viper.GetString("ld_sdk_key"), vzmgrClient)
serverOpts := &server.GRPCServerOptions{
DisableAuth: map[string]bool{
"/px.services.ConfigManagerService/GetConfigForVizier": true,
Expand Down
130 changes: 94 additions & 36 deletions src/cloud/config_manager/configmanagerpb/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/cloud/config_manager/configmanagerpb/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ message ConfigForVizierRequest {
vizierconfigpb.VizierSpec vz_spec = 2;
// Kubernetes version of the cluster Vizier is running on.
string k8s_version = 3 [ (gogoproto.customname) = "K8sVersion" ];
// ID of the Vizier (Cluster ID).
string vizier_id = 4 [ (gogoproto.customname) = "VizierID" ];
}

// ConfigForVizierResponse is the response to a ConfigForVizierRequest.
Expand Down
25 changes: 20 additions & 5 deletions src/cloud/config_manager/controllers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ type Server struct {
atClient atpb.ArtifactTrackerClient
deployKeyClient vzmgrpb.VZDeploymentKeyServiceClient
vzFeatureFlagClient VizierFeatureFlagClient
vzmgrClient vzmgrpb.VZMgrServiceClient
}

// NewServer creates GRPC handlers.
func NewServer(atClient atpb.ArtifactTrackerClient, deployKeyClient vzmgrpb.VZDeploymentKeyServiceClient, ldSDKKey string) *Server {
func NewServer(atClient atpb.ArtifactTrackerClient, deployKeyClient vzmgrpb.VZDeploymentKeyServiceClient, ldSDKKey string, vzmgrClient vzmgrpb.VZMgrServiceClient) *Server {
return &Server{
atClient: atClient,
deployKeyClient: deployKeyClient,
vzFeatureFlagClient: NewVizierFeatureFlagClient(ldSDKKey),
vzmgrClient: vzmgrClient,
}
}

Expand Down Expand Up @@ -217,12 +219,25 @@ func (s *Server) GetConfigForVizier(ctx context.Context,
}
AddDefaultTableStoreSize(tmplValues.PEMMemoryRequest, tmplValues.CustomPEMFlags)

// Next we inject any feature flags that we want to set for this org.
orgID, err := s.getOrgIDForDeployKey(tmplValues.DeployKey)
// Attempt to get the org ID from DeployKey, otherwise from the Vizier.
var orgID uuid.UUID
orgID, err = s.getOrgIDForDeployKey(tmplValues.DeployKey)
if err != nil || orgID == uuid.Nil {
log.WithError(err).Error("Error getting org ID from deploy key, skipping feature flag logic")
} else {
log.WithError(err).Error("Error getting org ID from deploy key")
}
if orgID == uuid.Nil && in.VizierID != "" {
resp, err := s.vzmgrClient.GetOrgFromVizier(ctx, utils.ProtoFromUUIDStrOrNil(in.VizierID))
orgID = utils.UUIDFromProtoOrNil(resp.OrgID)
if err != nil || orgID == uuid.Nil {
log.WithError(err).Error("Error getting org ID from Vizier")
}
}

// Next we inject any feature flags that we want to set for this org.
if orgID != uuid.Nil {
AddFeatureFlagsToTemplate(s.vzFeatureFlagClient, orgID, tmplValues)
} else {
log.Error("Skipping feature flag logic")
}

vzYamls, err := yamls.ExecuteTemplatedYAMLs(templatedYAMLs, vizieryamls.VizierTmplValuesToArgs(tmplValues))
Expand Down

0 comments on commit 1c328aa

Please sign in to comment.