Skip to content

Commit

Permalink
provide the ability to disable features
Browse files Browse the repository at this point in the history
part of: kiali#4737
  • Loading branch information
jmazzitelli committed Mar 24, 2022
1 parent d1e606b commit c9397b5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 19 deletions.
20 changes: 20 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ const (
DashboardsDiscoveryAuto = "auto"
)

// FeatureName is the enum type used for named features that can be disabled via KialiFeatureFlags.DisabledFeatures
type FeatureName string

const (
FeatureLogView FeatureName = "log-view"
)

// Global configuration for the application.
var configuration Config
var rwMutex sync.RWMutex
Expand Down Expand Up @@ -396,6 +403,7 @@ type CertificatesInformationIndicators struct {
// KialiFeatureFlags available from the CR
type KialiFeatureFlags struct {
CertificatesInformationIndicators CertificatesInformationIndicators `yaml:"certificates_information_indicators,omitempty" json:"certificatesInformationIndicators"`
DisabledFeatures []string `yaml:"disabled_features,omitempty" json:"disabledFeatures,omitempty"`
IstioInjectionAction bool `yaml:"istio_injection_action,omitempty" json:"istioInjectionAction"`
IstioUpgradeAction bool `yaml:"istio_upgrade_action,omitempty" json:"istioUpgradeAction"`
UIDefaults UIDefaults `yaml:"ui_defaults,omitempty" json:"uiDefaults,omitempty"`
Expand Down Expand Up @@ -617,6 +625,7 @@ func NewConfig() (c *Config) {
Enabled: true,
Secrets: []string{"cacerts", "istio-ca-secret"},
},
DisabledFeatures: []string{},
IstioInjectionAction: true,
IstioUpgradeAction: false,
UIDefaults: UIDefaults{
Expand Down Expand Up @@ -931,3 +940,14 @@ func IsIstioNamespace(namespace string) bool {
func IsRootNamespace(namespace string) bool {
return namespace == configuration.ExternalServices.Istio.RootNamespace
}

// IsFeatureDisabled will return true if the named feature is to be disabled.
func IsFeatureDisabled(featureName FeatureName) bool {
cfg := Get()
for _, f := range cfg.KialiFeatureFlags.DisabledFeatures {
if f == string(featureName) {
return true
}
}
return false
}
1 change: 1 addition & 0 deletions frontend/src/config/ServerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const defaultServerConfig: ComputedServerConfig = {
certificatesInformationIndicators: {
enabled: true
},
disabledFeatures: [],
istioInjectionAction: true,
istioUpgradeAction: false,
uiDefaults: {
Expand Down
40 changes: 21 additions & 19 deletions frontend/src/pages/WorkloadDetails/WorkloadDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,27 @@ class WorkloadDetails extends React.Component<WorkloadDetailsPageProps, Workload
);
tabsArray.push(trafficTab);

const logTab = (
<Tab title="Logs" eventKey={2} key={'Logs'}>
{hasPods ? (
<WorkloadPodLogs
namespace={this.props.match.params.namespace}
workload={this.props.match.params.workload}
pods={this.state.workload!.pods}
/>
) : (
<EmptyState variant={EmptyStateVariant.full}>
<Title headingLevel="h5" size="lg">
No logs for Workload {this.props.match.params.workload}
</Title>
<EmptyStateBody>There are no logs to display because the workload has no pods.</EmptyStateBody>
</EmptyState>
)}
</Tab>
);
tabsArray.push(logTab);
if (!serverConfig.kialiFeatureFlags.disabledFeatures || !serverConfig.kialiFeatureFlags.disabledFeatures.includes('log-view')) {
const logTab = (
<Tab title="Logs" eventKey={2} key={'Logs'}>
{hasPods ? (
<WorkloadPodLogs
namespace={this.props.match.params.namespace}
workload={this.props.match.params.workload}
pods={this.state.workload!.pods}
/>
) : (
<EmptyState variant={EmptyStateVariant.full}>
<Title headingLevel="h5" size="lg">
No logs for Workload {this.props.match.params.workload}
</Title>
<EmptyStateBody>There are no logs to display because the workload has no pods.</EmptyStateBody>
</EmptyState>
)}
</Tab>
);
tabsArray.push(logTab);
}

const inTab = (
<Tab title="Inbound Metrics" eventKey={3} key={'Inbound Metrics'}>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/ServerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface CertificatesInformationIndicators {

interface KialiFeatureFlags {
certificatesInformationIndicators: CertificatesInformationIndicators;
disabledFeatures: string[];
istioInjectionAction: boolean;
istioUpgradeAction: boolean;
uiDefaults: UIDefaults;
Expand Down
5 changes: 5 additions & 0 deletions handlers/workloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gorilla/mux"

"github.com/kiali/kiali/business"
"github.com/kiali/kiali/config"
"github.com/kiali/kiali/models"
)

Expand Down Expand Up @@ -205,6 +206,10 @@ func PodDetails(w http.ResponseWriter, r *http.Request) {

// PodLogs is the API handler to fetch logs for a single pod container
func PodLogs(w http.ResponseWriter, r *http.Request) {
if config.IsFeatureDisabled(config.FeatureLogView) {
RespondWithError(w, http.StatusForbidden, "Pod Logs access is disabled")
return
}
vars := mux.Vars(r)
queryParams := r.URL.Query()

Expand Down
5 changes: 5 additions & 0 deletions kiali.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func validateConfig() error {
log.Infof("Some validation errors will be ignored %v. If these errors do occur, they will still be logged. If you think the validation errors you see are incorrect, please report them to the Kiali team if you have not done so already and provide the details of your scenario. This will keep Kiali validations strong for the whole community.", cfg.KialiFeatureFlags.Validations.Ignore)
}

// log a info message if the user is disabling some features
if len(cfg.KialiFeatureFlags.DisabledFeatures) > 0 {
log.Infof("Some features are disabled: [%v]", strings.Join(cfg.KialiFeatureFlags.DisabledFeatures, ","))
}

return nil
}

Expand Down

0 comments on commit c9397b5

Please sign in to comment.