-
Notifications
You must be signed in to change notification settings - Fork 344
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
Add parents to varnish cache #7669
Changes from 6 commits
2fc572e
7b4a027
6a59baa
6a5c26a
312c673
fc55c79
c42d0d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -742,7 +742,7 @@ | |
|
||
// CheckSyncDSState retrieves and returns the DS Update status from Traffic Ops. | ||
// The metaData is this run's metadata. It must not be nil, and this function may add to it. | ||
func (r *TrafficOpsReq) CheckSyncDSState(metaData *t3cutil.ApplyMetaData) (UpdateStatus, error) { | ||
func (r *TrafficOpsReq) CheckSyncDSState(metaData *t3cutil.ApplyMetaData, cfg config.Cfg) (UpdateStatus, error) { | ||
updateStatus := UpdateTropsNotNeeded | ||
randDispSec := time.Duration(0) | ||
log.Debugln("Checking syncds state.") | ||
|
@@ -779,7 +779,7 @@ | |
} | ||
} else if !r.Cfg.IgnoreUpdateFlag { | ||
log.Errorln("no queued update needs to be applied. Running revalidation before exiting.") | ||
r.RevalidateWhileSleeping(metaData) | ||
r.RevalidateWhileSleeping(metaData, cfg) | ||
return UpdateTropsNotNeeded, nil | ||
} else { | ||
log.Errorln("Traffic Ops is signaling that no update is waiting to be applied.") | ||
|
@@ -1034,48 +1034,48 @@ | |
return nil | ||
} | ||
|
||
func pkgMetaDataToMap(pmd []string) map[string]bool { | ||
pkgMap := map[string]bool{} | ||
for _, pkg := range pmd { | ||
pkgMap[pkg] = true | ||
} | ||
return pkgMap | ||
} | ||
|
||
func pkgMatch(pkgMetaData []string, pk string) bool { | ||
for _, pkg := range pkgMetaData { | ||
if strings.Contains(pk, pkg) { | ||
return true | ||
} | ||
} | ||
return false | ||
|
||
} | ||
|
||
// ProcessPackagesWithMetaData will attempt to get installed package data from | ||
// t3c-apply-metadata.json and log the results. | ||
func (r *TrafficOpsReq) ProcessPackagesWithMetaData(packageMetaData []string) error { | ||
pkgs, err := getPackages(r.Cfg) | ||
pkgMdataMap := pkgMetaDataToMap(packageMetaData) | ||
if err != nil { | ||
return fmt.Errorf("getting packages: %w", err) | ||
} | ||
for _, pkg := range pkgs { | ||
fullPackage := pkg.Name + "-" + pkg.Version | ||
if pkgMdataMap[fullPackage] { | ||
log.Infof("package %s is assumed to be installed according to metadata file", fullPackage) | ||
r.Pkgs[fullPackage] = true | ||
} else if pkgMatch(packageMetaData, pkg.Name) { | ||
log.Infof("package %s is assumed to be installed according to metadata, but doesn't match traffic ops pkg", fullPackage) | ||
r.Pkgs[fullPackage] = true | ||
} else { | ||
log.Infof("package %s does not appear to be installed.", pkg.Name+"-"+pkg.Version) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (r *TrafficOpsReq) RevalidateWhileSleeping(metaData *t3cutil.ApplyMetaData) (UpdateStatus, error) { | ||
func (r *TrafficOpsReq) RevalidateWhileSleeping(metaData *t3cutil.ApplyMetaData, cfg config.Cfg) (UpdateStatus, error) { | ||
updateStatus, err := r.CheckRevalidateState(true) | ||
if err != nil { | ||
return updateStatus, err | ||
|
@@ -1099,7 +1099,7 @@ | |
t3cutil.WriteActionLog(t3cutil.ActionLogActionUpdateFilesReval, t3cutil.ActionLogStatusSuccess, metaData) | ||
} | ||
|
||
if err := r.StartServices(&updateStatus, metaData); err != nil { | ||
if err := r.StartServices(&updateStatus, metaData, cfg); err != nil { | ||
return updateStatus, errors.New("failed to start services: " + err.Error()) | ||
} | ||
|
||
|
@@ -1116,7 +1116,7 @@ | |
// StartServices reloads, restarts, or starts ATS as necessary, | ||
// according to the changed config files and run mode. | ||
// Returns nil on success or any error. | ||
func (r *TrafficOpsReq) StartServices(syncdsUpdate *UpdateStatus, metaData *t3cutil.ApplyMetaData) error { | ||
func (r *TrafficOpsReq) StartServices(syncdsUpdate *UpdateStatus, metaData *t3cutil.ApplyMetaData, cfg config.Cfg) error { | ||
serviceNeeds := t3cutil.ServiceNeedsNothing | ||
if r.Cfg.ServiceAction == t3cutil.ApplyServiceActionFlagRestart { | ||
serviceNeeds = t3cutil.ServiceNeedsRestart | ||
|
@@ -1138,13 +1138,17 @@ | |
serviceNeeds = t3cutil.ServiceNeedsReload | ||
} | ||
} | ||
packageName := "trafficserver" | ||
if cfg.CacheType == "varnish" { | ||
packageName = "varnish" | ||
} | ||
|
||
if (serviceNeeds == t3cutil.ServiceNeedsRestart || serviceNeeds == t3cutil.ServiceNeedsReload) && !r.IsPackageInstalled("trafficserver") { | ||
if (serviceNeeds == t3cutil.ServiceNeedsRestart || serviceNeeds == t3cutil.ServiceNeedsReload) && !r.IsPackageInstalled(packageName) { | ||
// TODO try to reload/restart anyway? To allow non-RPM installs? | ||
return errors.New("trafficserver needs " + serviceNeeds.String() + " but is not installed.") | ||
return errors.New(packageName + " needs " + serviceNeeds.String() + " but is not installed.") | ||
} | ||
|
||
svcStatus, _, err := util.GetServiceStatus("trafficserver") | ||
svcStatus, _, err := util.GetServiceStatus(packageName) | ||
if err != nil { | ||
return errors.New("getting trafficserver service status: " + err.Error()) | ||
} | ||
|
@@ -1161,7 +1165,7 @@ | |
if svcStatus != util.SvcRunning { | ||
startStr = "start" | ||
} | ||
if _, err := util.ServiceStart("trafficserver", startStr); err != nil { | ||
if _, err := util.ServiceStart(packageName, startStr); err != nil { | ||
t3cutil.WriteActionLog(t3cutil.ActionLogActionATSRestart, t3cutil.ActionLogStatusFailure, metaData) | ||
return errors.New("failed to restart trafficserver") | ||
} | ||
|
@@ -1188,7 +1192,13 @@ | |
log.Errorln("ATS configuration has changed. The new config will be picked up the next time ATS is started.") | ||
} else if serviceNeeds == t3cutil.ServiceNeedsReload { | ||
log.Infoln("ATS configuration has changed, Running 'traffic_ctl config reload' now.") | ||
if _, _, err := util.ExecCommand(config.TSHome+config.TrafficCtl, "config", "reload"); err != nil { | ||
reloadCommand := config.TSHome + config.TrafficCtl | ||
reloadArgs := []string{"config", "reload"} | ||
if cfg.CacheType == "varnish" { | ||
reloadCommand = "varnishreload" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be relying on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is done that way because Varnish currently is installed under root. So, |
||
reloadArgs = []string{} | ||
} | ||
if _, _, err := util.ExecCommand(reloadCommand, reloadArgs...); err != nil { | ||
t3cutil.WriteActionLog(t3cutil.ActionLogActionATSReload, t3cutil.ActionLogStatusFailure, metaData) | ||
|
||
if *syncdsUpdate == UpdateTropsNeeded { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cfgfile | ||
|
||
import ( | ||
"github.com/apache/trafficcontrol/cache-config/t3c-generate/config" | ||
"github.com/apache/trafficcontrol/cache-config/t3cutil" | ||
"github.com/apache/trafficcontrol/lib/varnishcfg" | ||
) | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. license header should go above imports, below package declaration |
||
|
||
// GetVarnishConfigs returns varnish configuration files | ||
// TODO: add varnishncsa and hitch configs | ||
func GetVarnishConfigs(toData *t3cutil.ConfigData, cfg config.Cfg) ([]t3cutil.ATSConfigFile, error) { | ||
vclBuilder := varnishcfg.NewVCLBuilder(toData) | ||
vcl, warnings, err := vclBuilder.BuildVCLFile() | ||
logWarnings("Generating varnish configuration files: ", warnings) | ||
|
||
configs := make([]t3cutil.ATSConfigFile, 0) | ||
// TODO: should be parameterized and generated from varnishcfg | ||
configs = append(configs, t3cutil.ATSConfigFile{ | ||
Name: "default.vcl", | ||
Text: vcl, | ||
Path: cfg.Dir, | ||
ContentType: "text/plain; charset=us-ascii", | ||
LineComment: "//", | ||
Secure: false, | ||
}) | ||
return configs, err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ COPY ./traffic_ops/toclientlib/ /go/src/github.com/apache/trafficcontrol/traffic | |
COPY ./traffic_ops/v4-client/ /go/src/github.com/apache/trafficcontrol/traffic_ops/v4-client/ | ||
COPY ./infrastructure/cdn-in-a-box/ /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/ | ||
|
||
# varnishcfg requires t3c for ToData struct and not needed for enroller | ||
RUN rm -rf /go/src/github.com/apache/trafficcontrol/lib/varnishcfg | ||
|
||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't worry about it; the enroller is pulling in a lot of things it doesn't strictly need. We can evaluate it if it becomes a problem, and try to clean it up a bit, but varnishcfg is small compared to the rest of the cruft so there's no point worrying about it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the comment can be improved, but it is not removed for optimization reasons. if we remove this line it won't be able to build the enroller binary because |
||
WORKDIR /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/enroller | ||
RUN set -o errexit -o nounset; \ | ||
go clean; \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
ARG BASE_IMAGE=rockylinux \ | ||
RHEL_VERSION=8 | ||
FROM ${BASE_IMAGE}:${RHEL_VERSION} AS common-varnish-cache-config-layers | ||
ARG RHEL_VERSION=8 | ||
# Makes RHEL_VERSION available at runtime | ||
ENV RHEL_VERSION="$RHEL_VERSION" | ||
|
||
RUN dnf module disable varnish -y && yum install -y epel-release | ||
|
||
RUN curl -s https://packagecloud.io/install/repositories/varnishcache/varnish73/script.rpm.sh | bash | ||
|
||
RUN yum install varnish-7.3.0 -y | ||
|
||
RUN dnf install -y bind-utils kyotocabinet-libs initscripts iproute net-tools nmap-ncat gettext autoconf automake libtool gcc-c++ cronie glibc-devel openssl-devel git perl && \ | ||
dnf install -y jq logrotate findutils && \ | ||
dnf clean all | ||
|
||
|
||
COPY infrastructure/cdn-in-a-box/varnish/run.sh infrastructure/cdn-in-a-box/traffic_ops/to-access.sh infrastructure/cdn-in-a-box/enroller/server_template.json / | ||
|
||
COPY infrastructure/cdn-in-a-box/dns/set-dns.sh \ | ||
infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh \ | ||
/usr/local/sbin/ | ||
|
||
|
||
COPY infrastructure/cdn-in-a-box/varnish/systemctl.sh /usr/bin/systemctl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it absolutely necessary to use systemd? Doing that in a Docker container is prone to problems and headaches There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
|
||
ARG ORT_RPM=infrastructure/cdn-in-a-box/cache/trafficcontrol-cache-config.rpm | ||
COPY $ORT_RPM / | ||
RUN rpm -Uvh /$(basename $ORT_RPM) &&\ | ||
rm /$(basename $ORT_RPM) | ||
|
||
COPY infrastructure/cdn-in-a-box/varnish/traffic_ops_ort.crontab /etc/cron.d/traffic_ops_ort-cron-template | ||
|
||
|
||
CMD /run.sh | ||
|
||
FROM common-varnish-cache-config-layers AS mid | ||
ENV CACHE_TYPE=mid | ||
COPY infrastructure/cdn-in-a-box/mid/init.d/ /opt/init.d/ | ||
|
||
FROM common-varnish-cache-config-layers AS edge | ||
ENV CACHE_TYPE=edge | ||
COPY infrastructure/cdn-in-a-box/edge/init.d/ /opt/init.d/ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like for varnish cache servers, this will cause it to look for configuration files under
/etc/trafficserver/etc/varnish
(by default I thinktsHome
is/opt/trafficserver
so that winds up being/opt/trafficserver/etc/trafficserver/etc/varnish
) - is that really how we want to structure that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the config dir will be either
home + /etc/trafficserver
,home + /etc/varnish
or if--trafficserver-home
flag is not used it will default to/opt/trafficerver/etc/trafficserver
and won't go into the if block (which is not good) other than that it will behome + /etc/varnish
for varnish case. For example specifying--trafficserver-home
flag with/opt/cache
will write the config to/opt/cache/etc/varnish
and that is what is done in varnish entrypoint.I think ultimately default home and config dir shouldn't be related to TS. However, this change will affect CIAB, tests, workflows and some other code depending on that. So, Maybe it would be better if it is done in a separate PR?