Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow VizierID to be used to find the Vizier's org #1650

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" ];
kpattaswamy marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
2 changes: 2 additions & 0 deletions src/cloud/api/controllers/config_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestConfigForVizier(t *testing.T) {
Namespace: "test-namespace",
VzSpec: vzSpec,
K8sVersion: "1.24.1",
VizierID: "test-id",
vihangm marked this conversation as resolved.
Show resolved Hide resolved
}

nameToYamlContent := make(map[string]string)
Expand All @@ -92,6 +93,7 @@ func TestConfigForVizier(t *testing.T) {
Namespace: "test-namespace",
VzSpec: vzSpec,
K8sVersion: "1.24.1",
VizierID: "test-id",
})
require.NoError(t, err)
assert.Equal(t, resp.NameToYamlContent["fileAName"], "fileAContent")
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
kpattaswamy marked this conversation as resolved.
Show resolved Hide resolved
}

// 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