This repository has been archived by the owner on Mar 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: audit operator actions to hostPath volume
- Loading branch information
Showing
4 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2017 The etcd-operator Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cluster | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/coreos/etcd-operator/pkg/spec" | ||
"github.com/coreos/etcd-operator/pkg/util/k8sutil" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"k8s.io/client-go/pkg/api/v1" | ||
) | ||
|
||
func NewAuditLogger(cl *spec.Cluster, lg *logrus.Entry) *logrus.Logger { | ||
if cl.Spec.SelfHosted == nil { | ||
return nil | ||
} | ||
|
||
mountPath := "/var/tmp/etcd-operator/" | ||
_, err := os.Stat(mountPath) | ||
if os.IsNotExist(err) { | ||
lg.Infof("mountPath(%v) not detected, no auditing will be performed: %v", mountPath, err) | ||
return nil | ||
} | ||
lg.Infof("detected the mountPath(%v): starting to audit operator actions to the mountPath", mountPath) | ||
|
||
fileName := mountPath + cl.Metadata.Name + ".log" | ||
logFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | ||
if err != nil { | ||
lg.Errorf("failed to open logfile(%v): %v", fileName, err) | ||
return nil | ||
} | ||
|
||
l := logrus.New() | ||
l.Out = logFile | ||
l.Infof("Starting audit logs for self-hosted etcd cluster: %v", cl.Metadata.Name) | ||
return l | ||
} | ||
|
||
func (c *Cluster) auditPodCreation(pod *v1.Pod, podCreationErr error) { | ||
if c.loggerSH == nil { | ||
return | ||
} | ||
|
||
if podCreationErr != nil { | ||
c.loggerSH.Infof("failed to create pod (%s): %v ", pod.Name, podCreationErr) | ||
return | ||
} | ||
|
||
podSpec, err := k8sutil.GetReadablePodSpec(pod) | ||
if err != nil { | ||
c.loggerSH.Infof("failed to get readable spec for pod(%v): %v ", pod.Name, err) | ||
} | ||
c.loggerSH.Infof("created pod (%s) with spec: %s\n", pod.Name, podSpec) | ||
} | ||
|
||
func (c *Cluster) auditPodDeletion(podName string, podDeletionErr error) { | ||
if c.loggerSH == nil { | ||
return | ||
} | ||
|
||
if podDeletionErr != nil { | ||
if !k8sutil.IsKubernetesResourceNotFoundError(podDeletionErr) { | ||
c.loggerSH.Infof("failed to delete pod (%s): %v ", podName, podDeletionErr) | ||
return | ||
} | ||
c.loggerSH.Infof("pod (%s) not found while trying to delete: %v ", podName) | ||
return | ||
} | ||
c.loggerSH.Infof("deleted pod (%s)", podName) | ||
} | ||
|
||
func (c *Cluster) auditClusterSpecUpdate(oldSpec, newSpec string) { | ||
if c.loggerSH == nil { | ||
return | ||
} | ||
c.loggerSH.Infof("spec update: \nOld:\n%v \nNew:\n%v\n", oldSpec, newSpec) | ||
} | ||
|
||
func (c *Cluster) auditMessage(msg string) { | ||
if c.loggerSH == nil { | ||
return | ||
} | ||
c.loggerSH.Infof(msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters