api server remove unused env vars (#347)

This commit is contained in:
RoyUP9 2021-10-13 14:14:14 +03:00 committed by GitHub
parent b40104b74c
commit 2706cd4d50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 25 deletions

View File

@ -42,20 +42,20 @@ var extensionsMap map[string]*tapApi.Extension // global
func main() { func main() {
flag.Parse() flag.Parse()
loadExtensions() loadExtensions()
hostMode := os.Getenv(shared.HostModeEnvVar) == "1"
tapOpts := &tap.TapOpts{HostMode: hostMode}
if !*tapperMode && !*apiServerMode && !*standaloneMode && !*harsReaderMode { if !*tapperMode && !*apiServerMode && !*standaloneMode && !*harsReaderMode {
panic("One of the flags --tap, --api or --standalone or --hars-read must be provided") panic("One of the flags --tap, --api or --standalone or --hars-read must be provided")
} }
filteringOptions := getTrafficFilteringOptions()
if *standaloneMode { if *standaloneMode {
api.StartResolving(*namespace) api.StartResolving(*namespace)
outputItemsChannel := make(chan *tapApi.OutputChannelItem) outputItemsChannel := make(chan *tapApi.OutputChannelItem)
filteredOutputItemsChannel := make(chan *tapApi.OutputChannelItem) filteredOutputItemsChannel := make(chan *tapApi.OutputChannelItem)
filteringOptions := getTrafficFilteringOptions()
hostMode := os.Getenv(shared.HostModeEnvVar) == "1"
tapOpts := &tap.TapOpts{HostMode: hostMode}
tap.StartPassiveTapper(tapOpts, outputItemsChannel, extensions, filteringOptions) tap.StartPassiveTapper(tapOpts, outputItemsChannel, extensions, filteringOptions)
go filterItems(outputItemsChannel, filteredOutputItemsChannel) go filterItems(outputItemsChannel, filteredOutputItemsChannel)
@ -75,6 +75,10 @@ func main() {
} }
filteredOutputItemsChannel := make(chan *tapApi.OutputChannelItem) filteredOutputItemsChannel := make(chan *tapApi.OutputChannelItem)
filteringOptions := getTrafficFilteringOptions()
hostMode := os.Getenv(shared.HostModeEnvVar) == "1"
tapOpts := &tap.TapOpts{HostMode: hostMode}
tap.StartPassiveTapper(tapOpts, filteredOutputItemsChannel, extensions, filteringOptions) tap.StartPassiveTapper(tapOpts, filteredOutputItemsChannel, extensions, filteringOptions)
socketConnection, _, err := websocket.DefaultDialer.Dial(*apiServerAddress, nil) socketConnection, _, err := websocket.DefaultDialer.Dial(*apiServerAddress, nil)
if err != nil { if err != nil {

View File

@ -103,7 +103,7 @@ func RunMizuTap() {
} }
defer finishMizuExecution(kubernetesProvider) defer finishMizuExecution(kubernetesProvider)
if err := createMizuResources(ctx, kubernetesProvider, mizuApiFilteringOptions, mizuValidationRules); err != nil { if err := createMizuResources(ctx, kubernetesProvider, mizuValidationRules); err != nil {
logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Error creating resources: %v", errormessage.FormatError(err))) logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Error creating resources: %v", errormessage.FormatError(err)))
return return
} }
@ -125,14 +125,14 @@ func readValidationRules(file string) (string, error) {
return string(newContent), nil return string(newContent), nil
} }
func createMizuResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, mizuApiFilteringOptions *api.TrafficFilteringOptions, mizuValidationRules string) error { func createMizuResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, mizuValidationRules string) error {
if !config.Config.IsNsRestrictedMode() { if !config.Config.IsNsRestrictedMode() {
if err := createMizuNamespace(ctx, kubernetesProvider); err != nil { if err := createMizuNamespace(ctx, kubernetesProvider); err != nil {
return err return err
} }
} }
if err := createMizuApiServer(ctx, kubernetesProvider, mizuApiFilteringOptions); err != nil { if err := createMizuApiServer(ctx, kubernetesProvider); err != nil {
return err return err
} }
@ -153,7 +153,7 @@ func createMizuNamespace(ctx context.Context, kubernetesProvider *kubernetes.Pro
return err return err
} }
func createMizuApiServer(ctx context.Context, kubernetesProvider *kubernetes.Provider, mizuApiFilteringOptions *api.TrafficFilteringOptions) error { func createMizuApiServer(ctx context.Context, kubernetesProvider *kubernetes.Provider) error {
var err error var err error
state.mizuServiceAccountExists, err = createRBACIfNecessary(ctx, kubernetesProvider) state.mizuServiceAccountExists, err = createRBACIfNecessary(ctx, kubernetesProvider)
@ -174,7 +174,6 @@ func createMizuApiServer(ctx context.Context, kubernetesProvider *kubernetes.Pro
PodImage: config.Config.AgentImage, PodImage: config.Config.AgentImage,
ServiceAccountName: serviceAccountName, ServiceAccountName: serviceAccountName,
IsNamespaceRestricted: config.Config.IsNsRestrictedMode(), IsNamespaceRestricted: config.Config.IsNsRestrictedMode(),
MizuApiFilteringOptions: mizuApiFilteringOptions,
SyncEntriesConfig: getSyncEntriesConfig(), SyncEntriesConfig: getSyncEntriesConfig(),
MaxEntriesDBSizeBytes: config.Config.Tap.MaxEntriesDBSizeBytes(), MaxEntriesDBSizeBytes: config.Config.Tap.MaxEntriesDBSizeBytes(),
Resources: config.Config.Tap.ApiServerResources, Resources: config.Config.Tap.ApiServerResources,

View File

@ -151,7 +151,6 @@ type ApiServerOptions struct {
PodImage string PodImage string
ServiceAccountName string ServiceAccountName string
IsNamespaceRestricted bool IsNamespaceRestricted bool
MizuApiFilteringOptions *api.TrafficFilteringOptions
SyncEntriesConfig *shared.SyncEntriesConfig SyncEntriesConfig *shared.SyncEntriesConfig
MaxEntriesDBSizeBytes int64 MaxEntriesDBSizeBytes int64
Resources configStructs.Resources Resources configStructs.Resources
@ -159,15 +158,10 @@ type ApiServerOptions struct {
} }
func (provider *Provider) CreateMizuApiServerPod(ctx context.Context, opts *ApiServerOptions) (*core.Pod, error) { func (provider *Provider) CreateMizuApiServerPod(ctx context.Context, opts *ApiServerOptions) (*core.Pod, error) {
marshaledFilteringOptions, err := json.Marshal(opts.MizuApiFilteringOptions)
if err != nil {
return nil, err
}
var marshaledSyncEntriesConfig []byte var marshaledSyncEntriesConfig []byte
if opts.SyncEntriesConfig != nil { if opts.SyncEntriesConfig != nil {
marshaledSyncEntriesConfig, err = json.Marshal(opts.SyncEntriesConfig) var err error
if err != nil { if marshaledSyncEntriesConfig, err = json.Marshal(opts.SyncEntriesConfig); err != nil {
return nil, err return nil, err
} }
} }
@ -219,14 +213,6 @@ func (provider *Provider) CreateMizuApiServerPod(ctx context.Context, opts *ApiS
}, },
Command: command, Command: command,
Env: []core.EnvVar{ Env: []core.EnvVar{
{
Name: shared.HostModeEnvVar,
Value: "1",
},
{
Name: shared.MizuFilteringOptionsEnvVar,
Value: string(marshaledFilteringOptions),
},
{ {
Name: shared.SyncEntriesConfigEnvVar, Name: shared.SyncEntriesConfigEnvVar,
Value: string(marshaledSyncEntriesConfig), Value: string(marshaledSyncEntriesConfig),